From: Richard Smith Date: Thu, 19 Nov 2015 02:36:35 +0000 (+0000) Subject: [coroutines] Tweak diagnostics to always use fully-qualified name for std::coroutine_... X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=569d398385a2db8b54e5b2e0ddbfa0b6ede877b8;p=clang [coroutines] Tweak diagnostics to always use fully-qualified name for std::coroutine_traits. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@253535 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/include/clang/Basic/DiagnosticSemaKinds.td b/include/clang/Basic/DiagnosticSemaKinds.td index 61f3653770..03bea29627 100644 --- a/include/clang/Basic/DiagnosticSemaKinds.td +++ b/include/clang/Basic/DiagnosticSemaKinds.td @@ -7971,14 +7971,14 @@ def ext_coroutine_without_co_await_co_yield : ExtWarn< def err_implied_std_coroutine_traits_not_found : Error< "you need to include before defining a coroutine">; def err_malformed_std_coroutine_traits : Error< - "std::coroutine_traits must be a class template">; + "'std::coroutine_traits' must be a class template">; def err_implied_std_coroutine_traits_promise_type_not_found : Error< - "this function cannot be a coroutine: %0 has no member named 'promise_type'">; + "this function cannot be a coroutine: %q0 has no member named 'promise_type'">; def err_implied_std_coroutine_traits_promise_type_not_class : Error< "this function cannot be a coroutine: %0 is not a class">; def err_coroutine_traits_missing_specialization : Error< "this function cannot be a coroutine: missing definition of " - "specialization %0">; + "specialization %q0">; } let CategoryName = "Documentation Issue" in { diff --git a/lib/Sema/SemaCoroutine.cpp b/lib/Sema/SemaCoroutine.cpp index a2a79001f0..210f30e2a4 100644 --- a/lib/Sema/SemaCoroutine.cpp +++ b/lib/Sema/SemaCoroutine.cpp @@ -82,6 +82,12 @@ static QualType lookupPromiseType(Sema &S, const FunctionProtoType *FnType, // The promise type is required to be a class type. QualType PromiseType = S.Context.getTypeDeclType(Promise); if (!PromiseType->getAsCXXRecordDecl()) { + // Use the fully-qualified name of the type. + auto *NNS = NestedNameSpecifier::Create(S.Context, nullptr, Std); + NNS = NestedNameSpecifier::Create(S.Context, NNS, false, + CoroTrait.getTypePtr()); + PromiseType = S.Context.getElaboratedType(ETK_None, NNS, PromiseType); + S.Diag(Loc, diag::err_implied_std_coroutine_traits_promise_type_not_class) << PromiseType; return QualType(); diff --git a/test/SemaCXX/coroutines.cpp b/test/SemaCXX/coroutines.cpp index 3e18187295..c82302c3c0 100644 --- a/test/SemaCXX/coroutines.cpp +++ b/test/SemaCXX/coroutines.cpp @@ -21,7 +21,12 @@ void no_specialization() { template struct std::coroutine_traits {}; int no_promise_type() { - co_await a; // expected-error {{this function cannot be a coroutine: 'coroutine_traits' has no member named 'promise_type'}} + co_await a; // expected-error {{this function cannot be a coroutine: 'std::coroutine_traits' has no member named 'promise_type'}} +} + +template<> struct std::coroutine_traits { typedef int promise_type; }; +double bad_promise_type(double) { + co_await a; // expected-error {{this function cannot be a coroutine: 'std::coroutine_traits::promise_type' (aka 'int') is not a class}} } struct promise; // expected-note {{forward declaration}}