Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Template Argument Deduction Broken in Clang 6 for Temporary Objects

Template argument deduction appears to be broken in Clang 6 for temporary objects.

g++ 8.1.0 compiles and runs the example correctly.

Clang 6.0.0 and 6.0.2 both error at the indicated line with this message:

error: expected unqualified-id
    Print{1,"foo"s,2};  /********** Broken in Clang **********/

All Other lines work correctly.

The behavior is the same in both cases whether -std=c++17 or -std=c++2a is used.

The Clang c++ Status Page indicates that template argument deduction was implemented as of Clang 5 (P0091R3, P0512R0).

Is this a bug? Are there workarounds (e.g. compiler flags, not code changes)?

example:

template<class ...Ts>
void print(Ts...ts){ (( cout << ... << ts )); }
template<class ...Ts>
struct Print {
    Print(Ts...ts){ (( cout << ... << ts )); }
};

int main(){
    Print{1,"foo"s,2}; /********** Broken in Clang **********/
    Print<int,string,int>{1,"foo"s,2};
    auto p1 = Print{1,"foo"s,2};
    Print p2{1,"foo"s,2};
    print(1,"foo"s,2);
}
like image 404
user9816683 Avatar asked May 21 '18 01:05

user9816683


1 Answers

This is Clang bug 34091.

Luckily, it is already fixed, and the trunk build of Clang compiles this without issue.

As far as I know, however, there is currently no way to work around this without code changes, short of upgrading to the next Clang release whenever that comes out.

like image 128
hlt Avatar answered Oct 23 '22 19:10

hlt