3

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

我能够将问题减少到以下问题

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

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

https://godbolt.org/z/ateuYW

<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 和 msvc 正在编译代码没有问题。

更改truetoif constexprfalsegcc 将编译它。

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

所以我的问题:

  1. 代码是有效的 c++ 还是我错过了什么?
  2. 我应该针对 gcc 提交错误吗?(我无法找到有关此问题的错误报告)
4

0 回答 0