我试着编译以下函数来看看gcc是怎么做的:
#include <stdint.h>
#include <stddef.h>
typedef struct giga
{
uint64_t g[0x10000000];
} giga;
uint64_t addfst(giga const *gptr, size_t num)
{
uint64_t retval = 0;
for (size_t i = 0; i < num; i++)
{
retval += gptr[i].g[0];
}
return retval;
}
Run Code Online (Sandbox Code Playgroud)
并且发现gcc最大化了我的记忆,将自己交换死亡.
我发现在优化时会发生这种情况-O3,并未尝试剖析确切的标志.在gcc.godbolt上测试函数显示这是gcc特定的,但是受到了4.8和4.9版本的影响.
这是一个真正的编译器错误,还是我的功能坏了?
这是一个10行的C++ 11程序,从我正在编写的程序中大大简化:
template <typename T> class Base { public:
template <typename S> Base(S x) {}
};
template <typename T> class Child : public Base<T> { public:
using Base<T>::Base;
};
template <> class Child<int> : public Base<int> { public:
using Base<int>::Base;
};
int main()
{
Child<int> child(8.0f);
}
Run Code Online (Sandbox Code Playgroud)
MSVC 2015产出:
1>------ Build started: Project: MyProject, Configuration: Debug Win32 ------
1> filename.cpp
1>path\to\filename(10): fatal error C1001: An internal error has occurred in the compiler.
1> (compiler file 'msc1.cpp', line 1393)
1> To …Run Code Online (Sandbox Code Playgroud) c++ visual-c++ c++11 internal-compiler-error visual-studio-2015
由于JDK错误,我设法编写了一些在使用JDK 1.8.0_131进行编译时导致错误的代码.我只用几行代码就可以重现这个问题 - 但是我找不到项目中使用错误的模式的位置.
我的目标是弄清楚我的项目中的哪些代码导致了这个错误,并应用了一种解决方法.
JDK-8074381错误报告中概述了该问题,并且只能在几行代码中复制.
public class Test {
public interface Foo<L> extends Function<Number, String> {
String apply(Number p);
}
private static final Foo CRASH = p -> "This will crash javac 1.8.0_131";
}
Run Code Online (Sandbox Code Playgroud)
当使用非参数化的lambda而不是非参数化的内部类(根据我认为的语言规范应该都是有效的)时,问题就会出现.所以
private static final Foo INNER = new Foo<Object>() {
@Override
public String apply(final Number p) {
return "This will not crash javac 1.8.0_131";
}
};
Run Code Online (Sandbox Code Playgroud)
工作良好.违规堆栈跟踪开始(为了您的理智而被截断):
An exception has occurred in the compiler (1.8.0_131). Please file a bug against the Java compiler …Run Code Online (Sandbox Code Playgroud) 玩数组的新位置,我出现(偶然/错误)使用以下代码:
#include <new>
struct X{};
int main()
{
char buf[256];
std::size_t n = 10;
X* p = new (buf) (X[n]); // incorrect way, parenthesis by mistake
//X* p = new (buf) X[n]; // correct way
}
Run Code Online (Sandbox Code Playgroud)
第三行main是不正确的,虽然它编译.不应该有任何括号.clang ++吐出来
警告:当类型在括号中时,数组不能具有动态大小
而gcc6输出
警告:ISO C++禁止可变长度数组[-Wvla] X*p = new(buf)(X [n]);
警告:必须在type-id周围没有括号的情况下指定非常量数组的新长度[-Wvla] X*p = new(buf)(X [n]);
然后在tree.h:4044中的tree_to_uhwi中使用内部编译器错误(ICE)崩溃.内部编译器错误仅出现在gcc> = 6中.
我的问题:如何解析/解释标记为"不正确"的行,为什么这些括号"错误"?*
*对于ICE,无论如何我都会填写一个bug.
编辑1我刚刚意识到ICE /警告与用户定义的类型无关,因此观察到相同的行为int而不是struct X.
编辑2 gcc6错误填写在这里.ICE不会出现在gcc5或更早版本中(仅出现警告,这是正确的).
看到新的发展.
我在Excel中有一个奇怪的问题.我有一个Worksheet_Change我正在使用的事件,我正在尝试调试它.我保存程序并重新打开它,突然之间编译器没有打破错误.事实上,它根本没有破坏!我会在分队的头部(以及接下来的三条线路)进行休息,这样就不会发生.我想也许事件没有启用......所以,我把一个消息框作为第一行代码之一.弹出消息框....即使在它的行上有中断.
这发生在另一个宏的特定行上之前,我尝试将所有内容复制到.txt文件中并将其粘贴回我的程序的早期版本.这工作了几个月,但问题现在又回来了.
编码并不是很重要,但我会将其粘贴在下面,以便进行踢腿和傻笑.这是在没有错误的情况下中止,我删除所有"错误"或不.我已经将代码剪切并粘贴到一个新的子中,它工作正常.我还检查了选项并检查了"中断所有错误".什么都没有,即使是未定义的调用也不会抛出错误,会阻止程序中止.
Private Sub Worksheet_Change(ByVal target As Range)
Application.EnableEvents = False
Dim aVar() As String
Dim iVar As Integer
On Error GoTo 0
MsgBox "you changed something" 'this is a msgbox that does pop up during execution, verifying that the sub did in fact, run.
Call iRandomNonsense 'this is a sub that does not exist which the compiler does not tell me about any more.
If target.Columns.Count = 1 Then
Select Case target.Column
Case 2
If …Run Code Online (Sandbox Code Playgroud) 我正在尝试编写可使我索引到函数的参数类型的代码:
template <typename R, typename... ARGS>
R function_return(R(*)(ARGS...));
template <typename R, typename... ARGS>
std::tuple<ARGS...> function_parameters(R(*)(ARGS...));
template <int I, typename T>
using get_type = typename std::conditional_t<(I < 0), std::tuple_element<static_cast<int>(std::tuple_size_v<T>) + I, T>, std::tuple_element<I, T>>::type;
template <int I, typename T>
using parameter_type = get_type<I, decltype(function_parameters(std::declval<T>()))>;
Run Code Online (Sandbox Code Playgroud)
Live Example (ICE under VS) Live Example (working on GCC)
但是当我尝试在visual-studio-2017上使用它时,出现内部编译器错误:
严重错误C1001:编译器中发生内部错误。
我还有另一种方法可以解决内部编译器错误吗?
c++ function-parameter internal-compiler-error template-variables visual-studio-2017
我在这里的第一篇文章,所以我将尽量保持简单。我正在尝试使用Processing创建一些质谱数据的图。我想写一个草图,将伪XML中的数据解析为表格,然后将该数据绘制为2轴(时间,mz)上的点,而第3轴即信号作为点的颜色。
在此阶段,我希望绘图为数据的尺寸。在我的测试数据中,这是x轴上的38个时间点,Y轴上的51 mz点,信号范围是0到12,000。实际数据集的边界在每个维度上都会大一百倍。
我的问题是,绘图的宽度和高度取决于数据,建立这些限制涉及一些代码。在处理中,您只能在void setup()之后立即调用size(),因此我将所有计算代码放在首位。这引发标题错误。我无法解决它,因此我将数据输出到三个csv文件,并从第二个草图开始,以导入该数据并对其进行绘制。我遇到了同样的错误。
确切的错误是期望EOF,位于''处,其中可能是一行中的第一个单词。根据我尝试的代码,它适用于,mzTable和if。
这是完整的第二个草图:
import java.io.*;
int debug = 1;
String target = "M1A crop.txt"; // test data
File file = new File(target);
// ~ ~ ~
String folderPath = file.getParent(); // target folder path
String name = file.getName();
String mzData = folderPath + "\\" + name + " - mz data.csv" ; // CSV file to open
String signalData = folderPath + "\\" + …Run Code Online (Sandbox Code Playgroud) 我尝试使用 Visual Studio 6 SP6 编译一个项目并得到以下结果:
usbcore.h(18) : fatal error C1001: INTERNAL COMPILER ERROR
(compiler file 'msc1.cpp', line 1794)
Please choose the Technical Support command on the Visual C++
Help menu, or open the Technical Support help file for more information
Run Code Online (Sandbox Code Playgroud)
usbcore.h 的第 18 行包含 include 指令:
18: #include "usbiface.h"
Run Code Online (Sandbox Code Playgroud)
空的或不存在的 usbiface.h 会产生同样的错误。我评论了这一行并得到了相同的错误,但对于下一个包含文件。
总结一下:每个#include引用公共项目标头的指令都会发生编译器错误。
我尝试调用GSL库的蒙特卡罗积分子程序来进行一些数值计算。因为我的 for 循环相当简单,这意味着不同运行的结果是独立的,所以我预计使用 OpenMP 进行并行化应该非常简单。然而,当我编译它时,它总是显示“内部编译器错误:分段错误”,并且什么也没生成。这是我的代码:
#include <stdlib.h>
#include <omp.h>
#include <gsl/gsl_math.h>
#include <gsl/gsl_monte.h>
#include <gsl/gsl_monte_vegas.h>
#include <math.h>
double
Reg1 (double *x, double t, size_t dim, void *params)
{
return sin(x[1])*cos(t*t)*x[0]*x[0]*cos(x[0])*cos(3*x[0]);
}
void
display_results (char *title, double result, double error)
{
printf ("%s ==================\n", title);
printf ("result = % .10f\n", result);
printf ("sigma = % .10f\n\n", error);
}
void
VEGAS_integration_routine (double (*function)(double *, size_t, void *),
double xl[], double xu[], size_t calls, gsl_rng * r)
{
double res, err;
gsl_monte_function Function …Run Code Online (Sandbox Code Playgroud) 我正在使用Visual Studio 2015 Update 3.
我收到一个致命的错误:
(代码C1001):编译器中发生内部错误.
这是代码:
template<typename T>
constexpr T epsilon = std::numeric_limits<T>::epsilon();
Run Code Online (Sandbox Code Playgroud)
我读过它是在Visual Studio Update 2中修复的.有人可以解释我为什么会收到此错误吗?提前致谢.
c++ visual-c++ internal-compiler-error c++14 visual-studio-2015
我正在尝试使用pgCC编译器编译我的C++程序,该程序使用MPICH和NAG C库(我使用NAG生成随机数).
但是,编译器给了我以下错误消息:
PGCC-S-0000-Internal compiler error. linearize: bad ili #: 0 (mpisim.C: 225)
PGCC-S-0000-Internal compiler error. gen_aili: unrec. ili opcode: 0 (mpisim.C: 225)
PGCC-S-0000-Internal compiler error. linearize: bad ili #: 0 (mpisim.C: 266)
PGCC-S-0000-Internal compiler error. gen_aili: unrec. ili opcode: 0 (mpisim.C: 266)
PGCC/x86 Linux 12.4-0: compilation completed with severe errors
Run Code Online (Sandbox Code Playgroud)
我不知道这些消息是指什么.有人可以向我解释他们的意思吗?
有没有办法让我弄清楚问题线的位置?255in 是否(mpisim.C: 225)表示我的代码中的行号?
以以下最小示例为例:
#include <stdio.h>
bool test(){
for (int i = 0; i < 1024; i++)
{
printf("i=%d\n", i);
}
}
int main(){
test();
return 0;
}
Run Code Online (Sandbox Code Playgroud)
test函数中的 return 语句丢失的地方。如果我像这样运行示例:
g++ main.cpp -o main && ./main
Run Code Online (Sandbox Code Playgroud)
然后循环在 1024 次迭代后中止。但是,如果我在打开优化的情况下运行示例:
g++ -O3 main.cpp -o main && ./main
Run Code Online (Sandbox Code Playgroud)
然后这是优化的,我得到一个无限循环。
此行为在g++version10.3.1和clang++version之间保持一致10.0.1。如果我添加 return 语句或将函数的返回类型更改为void.
我很好奇:这会被认为是编译器错误吗?或者这是可以接受的,因为缺少 return 语句是未定义的行为,因此我们失去了对这个函数中发生的事情的所有保证?
#include <limits>
#include <cstdint>
#include <iostream>
template<typename T>
T f(T const a = std::numeric_limits<T>::min(),
T const b = std::numeric_limits<T>::max())
{
if (a >= b)
{
throw 1;
}
auto n = static_cast<std::uint64_t>(b - a + 1);
if (0 == n)
{
n = 1;
}
return n;
}
int main()
{
std::cout << f<int>() << std::endl;
}
Run Code Online (Sandbox Code Playgroud)
g++-11 -std=c++20 -O2应该输出0比其他1!
clang++ 没问题。如果我-O2改为-O0,g++-11 也可以。
参见:在线演示
为什么 g++ -O2 包含一个错误而 -O0 可以?