From: Richard Smith Date: Wed, 8 Feb 2017 01:27:29 +0000 (+0000) Subject: Diagnose an attempt to give a deduction-guide a function body. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=7b0f692041cfa8e45f1d3762299924931276fffe;p=clang Diagnose an attempt to give a deduction-guide a function body. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@294397 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/include/clang/Basic/DiagnosticSemaKinds.td b/include/clang/Basic/DiagnosticSemaKinds.td index b04ba2b5ed..04a404e104 100644 --- a/include/clang/Basic/DiagnosticSemaKinds.td +++ b/include/clang/Basic/DiagnosticSemaKinds.td @@ -1972,6 +1972,8 @@ def err_deduction_guide_name_not_class_template : Error< "cannot specify deduction guide for " "%select{|function template|variable template|alias template|" "template template parameter|dependent template name}0 %1">; +def err_deduction_guide_defines_function : Error< + "deduction guide cannot have a function definition">; // C++1y deduced return types def err_auto_fn_deduction_failure : Error< diff --git a/lib/Sema/SemaDeclCXX.cpp b/lib/Sema/SemaDeclCXX.cpp index 1ae89ea89b..e3310b60a2 100644 --- a/lib/Sema/SemaDeclCXX.cpp +++ b/lib/Sema/SemaDeclCXX.cpp @@ -8129,6 +8129,9 @@ void Sema::CheckDeductionGuideDeclarator(Declarator &D, QualType &R, // FIXME: Check that the return type can instantiate to a specialization of // the template specified as the deduction-guide's name. + + if (D.isFunctionDefinition()) + Diag(D.getIdentifierLoc(), diag::err_deduction_guide_defines_function); } //===----------------------------------------------------------------------===// diff --git a/test/CXX/temp/temp.deduct.guide/p1.cpp b/test/CXX/temp/temp.deduct.guide/p1.cpp index fb0a26a5c7..8dd0720669 100644 --- a/test/CXX/temp/temp.deduct.guide/p1.cpp +++ b/test/CXX/temp/temp.deduct.guide/p1.cpp @@ -77,11 +77,11 @@ const volatile static constexpr inline A(int(&)[29]) -> A; // expected-erro A(int(&)[30]) const -> A; // expected-error {{deduction guide cannot have 'const' qualifier}} -// FIXME: No definition is allowed. -A(int(&)[40]) -> A {} -A(int(&)[41]) -> A = default; // expected-error {{only special member functions may be defaulted}} -A(int(&)[42]) -> A = delete; -A(int(&)[43]) -> A try {} catch (...) {} +// No definition is allowed. +A(int(&)[40]) -> A {} // expected-error {{deduction guide cannot have a function definition}} +A(int(&)[41]) -> A = default; // expected-error {{deduction guide cannot have a function definition}} expected-error {{only special member functions may be defaulted}} +A(int(&)[42]) -> A = delete; // expected-error {{deduction guide cannot have a function definition}} +A(int(&)[43]) -> A try {} catch (...) {} // expected-error {{deduction guide cannot have a function definition}} #ifdef CLASS };