5

Related, but (IMHO) different: Nested template argument deduction for class templates not working

The following C++17 code is rejected from GCC 8, but clang compiles it without any issues. The GCC's error message is included as a comment just before the problematic line.

Which compiler is correct here?

https://godbolt.org/z/WG6f7G

template<class T>
struct Foo {
    Foo(T) {}
};

template<class T>
struct Bar {
     Bar(T) {};
};

void works() {
    Bar bar{1};// {}
    Foo foo(bar);// ()
}

void works_too() {
    Foo foo{Bar{1}};// {{}}
}

void error_in_gcc() {
// error: 'auto' parameter not permitted in this context
    Foo foo(Bar{1});// ({})
}

void but_this_works() {
    Foo(Bar{1});// ({})
}
Rakete1111
  • 47,013
  • 16
  • 123
  • 162
Julius
  • 1,816
  • 10
  • 14
  • 3
    Definite gcc bug. Pretty sure I filed something like this but can't find it right now. – Barry Jan 25 '19 at 17:10
  • 1
    @Barry Are you talking about https://gcc.gnu.org/bugzilla/show_bug.cgi?id=87709 – Rakete1111 Jan 25 '19 at 17:17
  • 1
    I suspect paring bug of gcc (parsing it a function declaration). – Jarod42 Jan 25 '19 at 17:20
  • @Rakete1111 Found it, [81486](https://gcc.gnu.org/bugzilla/show_bug.cgi?id=81486). But that was _only_ for `()`, not for a specific argument. – Barry Jan 25 '19 at 18:21
  • 1
    Filed [89062](https://gcc.gnu.org/bugzilla/show_bug.cgi?id=89062). – Barry Jan 25 '19 at 18:26
  • @Rakete1111 Actually in retrospect, it might be the same bug as 87709 – Barry Jan 25 '19 at 18:31
  • GCC gives even more confusing errors for `Foo f(Bar(x) / 1);` (with suitably declared `x` and `operator/`). Apparently GCC does not realize that this cannot be a valid function declaration (until it's too late). – cpplearner Jan 25 '19 at 19:55

1 Answers1

2

Comments to this question state that this is a GCC bug. It has been filed as GCC bug report 89062.

Julius
  • 1,816
  • 10
  • 14