C++ 如果constexpr gcc错误

C++ 如果constexpr gcc错误,c++,gcc,if-constexpr,C++,Gcc,If Constexpr,我注意到我的代码库不再使用gcc编译 我能够将问题归结为以下几点 struct bar { int foo(){return 0;} }; int foobar() { if constexpr(true) { return 0; } else { return [](){ return bar{}; }().foo(); } } :在函数“int foobar()”中: :11:10:

我注意到我的代码库不再使用gcc编译

我能够将问题归结为以下几点

struct bar {
    int foo(){return 0;}
};

int foobar() {
    if constexpr(true) {
        return 0;
    } else {
        return [](){
            return bar{};
        }().foo();
    }
}

:在函数“int foobar()”中:
:11:10:错误:“void”的使用无效
9 |返回[](){
|                ~~~~~
10 |返回条{};
|             ~~~~~~~~~~~~~
11 |}().foo();
|         ~^~
:11:13:错误:应为“;”在“foo”之前
11 |}().foo();
|             ^~~
|             ;
:11:13:错误:“foo”未在此作用域中声明
11 |}().foo();
|             ^~~
clang和msvc编译代码没有问题

if constexpr
中的
true
更改为
false
,gcc也将编译它

我假设gcc并没有完全解析导致奇怪错误的错误部分

因此,我的问题是:

  • 是代码有效C++还是我错过什么?< /LI>
  • 我应该针对gcc提交一个bug吗?(我找不到这个问题的bug报告)

  • 一些实验表明,gcc只是不喜欢
    constepr
    if中被忽略部分的lambdas。应该明确地将错误归档。您可能希望在gcc错误报告中发布一个指向gcc错误的链接
    <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();
    
          |             ^~~