r294397 - Diagnose an attempt to give a deduction-guide a function body.

Richard Smith via cfe-commits cfe-commits at lists.llvm.org
Tue Feb 7 17:27:29 PST 2017


Author: rsmith
Date: Tue Feb  7 19:27:29 2017
New Revision: 294397

URL: http://llvm.org/viewvc/llvm-project?rev=294397&view=rev
Log:
Diagnose an attempt to give a deduction-guide a function body.

Modified:
    cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
    cfe/trunk/lib/Sema/SemaDeclCXX.cpp
    cfe/trunk/test/CXX/temp/temp.deduct.guide/p1.cpp

Modified: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td?rev=294397&r1=294396&r2=294397&view=diff
==============================================================================
--- cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td Tue Feb  7 19:27:29 2017
@@ -1972,6 +1972,8 @@ def err_deduction_guide_name_not_class_t
   "cannot specify deduction guide for "
   "%select{<error>|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<

Modified: cfe/trunk/lib/Sema/SemaDeclCXX.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDeclCXX.cpp?rev=294397&r1=294396&r2=294397&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaDeclCXX.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDeclCXX.cpp Tue Feb  7 19:27:29 2017
@@ -8129,6 +8129,9 @@ void Sema::CheckDeductionGuideDeclarator
 
   // 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);
 }
 
 //===----------------------------------------------------------------------===//

Modified: cfe/trunk/test/CXX/temp/temp.deduct.guide/p1.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CXX/temp/temp.deduct.guide/p1.cpp?rev=294397&r1=294396&r2=294397&view=diff
==============================================================================
--- cfe/trunk/test/CXX/temp/temp.deduct.guide/p1.cpp (original)
+++ cfe/trunk/test/CXX/temp/temp.deduct.guide/p1.cpp Tue Feb  7 19:27:29 2017
@@ -77,11 +77,11 @@ const volatile static constexpr inline A
 
 A(int(&)[30]) const -> A<int>; // expected-error {{deduction guide cannot have 'const' qualifier}}
 
-// FIXME: No definition is allowed.
-A(int(&)[40]) -> A<int> {}
-A(int(&)[41]) -> A<int> = default; // expected-error {{only special member functions may be defaulted}}
-A(int(&)[42]) -> A<int> = delete;
-A(int(&)[43]) -> A<int> try {} catch (...) {}
+// No definition is allowed.
+A(int(&)[40]) -> A<int> {} // expected-error {{deduction guide cannot have a function definition}}
+A(int(&)[41]) -> A<int> = default; // expected-error {{deduction guide cannot have a function definition}} expected-error {{only special member functions may be defaulted}}
+A(int(&)[42]) -> A<int> = delete; // expected-error {{deduction guide cannot have a function definition}}
+A(int(&)[43]) -> A<int> try {} catch (...) {} // expected-error {{deduction guide cannot have a function definition}}
 
 #ifdef CLASS
 };




More information about the cfe-commits mailing list