Hi, sorry to ask a daft question but why does the following code
compile fine with clang/clang++ ?
int main()
{
int a = _Generic(1, int: 2);
int &x = a;
}
As far as I know, it does not conform to either C or C++ ( I believe
_Generic is not supported by C++ ? ).
It fails to compile with g++.
Thanks and Regards,
Prathamesh
That appears to be a bug; if you'd like, you could file a bug report
at http://llvm.org/bugs on it.
Good catch!
~Aaron
Actually, I take that back, we treat it as a language extension (not
certain how I missed that). You should be seeing an extension warning:
"generic selections are a C11-specific feature" depending on your
compiler flags.
So I wouldn't file a bug just yet. What flags are you passing in to
the compiler?
~Aaron
Actually, I take that back, we treat it as a language extension (not
certain how I missed that). You should be seeing an extension warning:
"generic selections are a C11-specific feature" depending on your
compiler flags.
So I wouldn't file a bug just yet. What flags are you passing in to
the compiler?
I hadn't passed any flags initially. However when i passsed -Wc11-extensions,
i got the warning:
x.cpp:3:11: warning: generic selections are a C11-specific feature
[-Wc11-extensions]
int a = _Generic (1, int: 2);
But when I pass no options, it compiles silently.
Actually, I take that back, we treat it as a language extension (not
certain how I missed that). You should be seeing an extension warning:
"generic selections are a C11-specific feature" depending on your
compiler flags.
So I wouldn't file a bug just yet. What flags are you passing in to
the compiler?
I hadn't passed any flags initially. However when i passsed -Wc11-extensions,
i got the warning:
x.cpp:3:11: warning: generic selections are a C11-specific feature
[-Wc11-extensions]
int a = _Generic (1, int: 2);
But when I pass no options, it compiles silently.
~Aaron
That appears to be a bug; if you'd like, you could file a bug report
at http://llvm.org/bugs on it.
Good catch!
~Aaron
Hi, sorry to ask a daft question but why does the following code
compile fine with clang/clang++ ?
int main()
{
int a = _Generic(1, int: 2);
int &x = a;
}
As far as I know, it does not conform to either C or C++ ( I believe
_Generic is not supported by C++ ? ).
It fails to compile with g++.
The same thing is true for _Static_assert.
This compiled without any error/warning too (without passing any option):
int main()
{
int a;
int &x = a;
_Static_assert(1, "hello world");
}
Are (most of) c11 features treated as language extensions ?
Yes, they appear to be. It seems that language extension diagnostics
are ignored by default, which is why you need to enable them
explicitly. For instance, with -pedantic, et al.
~Aaron