From: Richard Smith Date: Sat, 4 May 2013 04:19:27 +0000 (+0000) Subject: Say 'decltype(auto)' not 'auto' as appropriate in mismatched-deduction diagnostic. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=ffd015e316fff53f23e9ffd4907b88b8706e4183;p=clang Say 'decltype(auto)' not 'auto' as appropriate in mismatched-deduction diagnostic. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@181103 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/include/clang/Basic/DiagnosticSemaKinds.td b/include/clang/Basic/DiagnosticSemaKinds.td index f43a7d1338..d7347e9c31 100644 --- a/include/clang/Basic/DiagnosticSemaKinds.td +++ b/include/clang/Basic/DiagnosticSemaKinds.td @@ -1454,7 +1454,8 @@ def err_auto_var_deduction_failure_from_init_list : Error< def err_auto_new_deduction_failure : Error< "new expression for type %0 has incompatible constructor argument of type %1">; def err_auto_different_deductions : Error< - "'auto' deduced as %0 in declaration of %1 and deduced as %2 in declaration of %3">; + "'%select{auto|decltype(auto)}0' deduced as %1 in declaration of %2 and " + "deduced as %3 in declaration of %4">; def err_implied_std_initializer_list_not_found : Error< "cannot deduce type of initializer list because std::initializer_list was " "not found; include ">; diff --git a/lib/Sema/SemaDecl.cpp b/lib/Sema/SemaDecl.cpp index f5b4823fdb..f7826771cc 100644 --- a/lib/Sema/SemaDecl.cpp +++ b/lib/Sema/SemaDecl.cpp @@ -8212,6 +8212,7 @@ Sema::BuildDeclaratorGroup(Decl **Group, unsigned NumDecls, } else if (DeducedCanon != UCanon) { Diag(D->getTypeSourceInfo()->getTypeLoc().getBeginLoc(), diag::err_auto_different_deductions) + << (AT->isDecltypeAuto() ? 1 : 0) << Deduced << DeducedDecl->getDeclName() << U << D->getDeclName() << DeducedDecl->getInit()->getSourceRange() diff --git a/test/CXX/dcl.dcl/dcl.spec/dcl.type/dcl.spec.auto/p6-1y.cpp b/test/CXX/dcl.dcl/dcl.spec/dcl.type/dcl.spec.auto/p6-1y.cpp index cfaed71832..25b5f1984c 100644 --- a/test/CXX/dcl.dcl/dcl.spec/dcl.type/dcl.spec.auto/p6-1y.cpp +++ b/test/CXX/dcl.dcl/dcl.spec/dcl.type/dcl.spec.auto/p6-1y.cpp @@ -60,3 +60,7 @@ decltype(auto) ((((((v1)))))) = 0; // ok decltype(auto) v2[1] = { 0 }; // expected-error {{cannot form array of 'decltype(auto)'}} decltype(auto) &v3 = { 0 }; // expected-error {{cannot form reference to 'decltype(auto)'}} decltype(auto) *v4 = { 0 }; // expected-error {{cannot form pointer to 'decltype(auto)'}} + +auto multi1a = 0, &multi1b = multi1a; +auto multi1c = multi1a, multi1d = multi1b; +decltype(auto) multi1e = multi1a, multi1f = multi1b; // expected-error {{'decltype(auto)' deduced as 'int' in declaration of 'multi1e' and deduced as 'int &' in declaration of 'multi1f'}}