Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

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);
}
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
272 views
Welcome To Ask or Share your Answers For Others

1 Answer

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...