I noticed my code base not longer compiling with gcc.
I was able to reduce the problem to the following
struct bar {
int foo(){return 0;}
};
int foobar() {
if constexpr(true) {
return 0;
} else {
return [](){
return bar{};
}().foo();
}
}
<source>: In function 'int foobar()':
<source>:11:10: error: invalid use of 'void'
9 | return [](){
| ~~~~~
10 | return bar{};
| ~~~~~~~~~~~~~
11 | }().foo();
| ~^~
<source>:11:13: error: expected ';' before 'foo'
11 | }().foo();
| ^~~
| ;
<source>:11:13: error: 'foo' was not declared in this scope
11 | }().foo();
| ^~~
clang and msvc are compiling the code without problems.
Changing the true
in the if constexpr
to false
and also gcc will compile it.
I assume that gcc is not fully parsing the false part of the which leads to the strange error.
So my question:
- Is the code valid c++ or do I miss something?
- Should I file a bug against gcc?(I was not able to find a bug report for this issue)