Quantcast
Channel: Active questions tagged gcc - Stack Overflow
Viewing all articles
Browse latest Browse all 22113

if constexpr gcc bug

$
0
0

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();
    }
}

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 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:

  1. Is the code valid c++ or do I miss something?
  2. Should I file a bug against gcc?(I was not able to find a bug report for this issue)

Viewing all articles
Browse latest Browse all 22113

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>