From: Benjamin Kramer Date: Fri, 12 Aug 2016 09:19:34 +0000 (+0000) Subject: [C++1z] Fix crash when decomposing structs with anonymous members. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=ad674ae13e64a272012eed3fedc4daf4fbdeceda;p=clang [C++1z] Fix crash when decomposing structs with anonymous members. The diagnostic format was invalid. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@278487 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/include/clang/Basic/DiagnosticSemaKinds.td b/include/clang/Basic/DiagnosticSemaKinds.td index bc628143d5..788ff19211 100644 --- a/include/clang/Basic/DiagnosticSemaKinds.td +++ b/include/clang/Basic/DiagnosticSemaKinds.td @@ -405,8 +405,8 @@ def err_decomp_decl_non_public_base : Error< def err_decomp_decl_non_public_member : Error< "cannot decompose non-public member %0 of %1">; def err_decomp_decl_anon_union_member : Error< - "cannot decompose class type %1 because it has an anonymous " - "%select{struct|union} member">; + "cannot decompose class type %0 because it has an anonymous " + "%select{struct|union}1 member">; def err_decomp_decl_std_tuple_element_not_specialized : Error< "cannot decompose this type; 'std::tuple_element<%0>::type' " "does not name a type">; diff --git a/test/CXX/dcl.decl/dcl.decomp/p4.cpp b/test/CXX/dcl.decl/dcl.decomp/p4.cpp index ea225cbf9a..c461eb6f54 100644 --- a/test/CXX/dcl.decl/dcl.decomp/p4.cpp +++ b/test/CXX/dcl.decl/dcl.decomp/p4.cpp @@ -32,6 +32,25 @@ namespace NonPublicMembers { } } +namespace AnonymousMember { + struct Struct { + struct { // expected-note {{declared here}} + int i; + }; + }; + + struct Union { + union { // expected-note {{declared here}} + int i; + }; + }; + + void test() { + auto [a1] = Struct(); // expected-error {{cannot decompose class type 'AnonymousMember::Struct' because it has an anonymous struct member}} + auto [a2] = Union(); // expected-error {{cannot decompose class type 'AnonymousMember::Union' because it has an anonymous union member}} + } +} + namespace MultipleClasses { struct B : A { int a;