使用VS2013 Update 2,我偶然发现了一些奇怪的错误消息:
// test.c
int main(void)
{
struct foo {
int i;
float f;
};
struct bar {
unsigned u;
struct foo foo;
double d;
};
struct foo some_foo = {
.i = 1,
.f = 2.0
};
struct bar some_bar = {
.u = 3,
// error C2440 : 'initializing' : cannot convert from 'foo' to 'int'
.foo = some_foo,
.d = 4.0
};
// Works fine
some_bar.foo = some_foo;
return 0;
}
Run Code Online (Sandbox Code Playgroud)
GCC和Clang都接受了.
我错过了什么或这段代码是否暴露了编译器错误?
c designated-initializer compiler-bug visual-studio-2013 msvc12
在此代码段中,指向VLA的指针用于更轻松地访问大型查找表:
#pragma GCC diagnostic warning "-Wcast-qual"
char
lookup(int a, int b, int c, char const *raw, int x, int y, int z)
{
typedef char const (*DATA_PTR)[a][b][c];
DATA_PTR data = (DATA_PTR)raw;
return (*data)[x][y][z];
}
Run Code Online (Sandbox Code Playgroud)
GCC 6.2.0扼杀它,而Clang 4.0.0(主干)编译得很好,两者都-Wcast-qual启用了.
In function 'lookup':
warning: cast discards 'const' qualifier from pointer target type [-Wcast-qual]
DATA_PTR data = (DATA_PTR)raw;
^
Run Code Online (Sandbox Code Playgroud)
代码按预期方式运行.
我的猜测是GCC混淆了"指向const元素的VLA的指针"和"指向const VLA的指针",但我达到了......
有没有办法在没有摆弄警告的情况下关闭GCC?这是GCC的错误吗?
EDIT1:
有关实际代码的详细信息:
struct table {
int a;
int b;
int c;
char …Run Code Online (Sandbox Code Playgroud) 我正在尝试使用 SPIR-V专门化常量来定义统一块中数组的大小。
#version 460 core
layout(constant_id = 0) const uint count = 0;
layout(binding = 0) uniform Uniform
{
vec4 foo[count];
uint bar[count];
};
void main() {}
Run Code Online (Sandbox Code Playgroud)
count = 0在着色器中声明 时,编译失败并显示:
array size must be a positive integer
Run Code Online (Sandbox Code Playgroud)
当count = 1特化为 5 时,代码可以编译,但在运行时链接失败,并抱怨别名:
error: different uniforms (named Uniform.foo[4] and Uniform.bar[3]) sharing the same offset within a uniform block (named Uniform) between shaders
error: different uniforms (named Uniform.foo[3] and Uniform.bar[2]) sharing the same offset within a …Run Code Online (Sandbox Code Playgroud)