nwilson created this revision.
nwilson added reviewers: rsmith, faisalv, hubert.reinterpretcast, aaron.ballman.
nwilson added a subscriber: cfe-commits.

Adding checks and diagnostics which fall under Concepts TS[dcl.spec.concept]p5:
function concepts are required to have 'bool' return type. 
Adding checks and  diagnostics which fall under Concepts TS[dcl.spec.concept]p6:
variable concepts are required to have 'bool' declaration type.

Remove a test in Parser which caused a regression due to the new checks.

http://reviews.llvm.org/D16163

Files:
  include/clang/Basic/DiagnosticSemaKinds.td
  lib/Sema/SemaDecl.cpp
  test/CXX/concepts-ts/dcl.dcl/dcl.spec/dcl.spec.concept/p5.cpp
  test/CXX/concepts-ts/dcl.dcl/dcl.spec/dcl.spec.concept/p6.cpp
  test/Parser/cxx-concept-declaration.cpp

Index: test/Parser/cxx-concept-declaration.cpp
===================================================================
--- test/Parser/cxx-concept-declaration.cpp
+++ test/Parser/cxx-concept-declaration.cpp
@@ -13,9 +13,6 @@
 template<int N>
 A<void>::Boolean concept C3(!0);
 
-template<typename T, int = 0>
-concept auto C4(void) -> bool { return true; }
-
 constexpr int One = 1;
 
 template <typename>
Index: test/CXX/concepts-ts/dcl.dcl/dcl.spec/dcl.spec.concept/p6.cpp
===================================================================
--- /dev/null
+++ test/CXX/concepts-ts/dcl.dcl/dcl.spec/dcl.spec.concept/p6.cpp
@@ -0,0 +1,22 @@
+// RUN:  %clang_cc1 -std=c++14 -fconcepts-ts -x c++ -verify %s
+
+template<typename T>
+concept bool vc { true };
+
+template<typename T>
+struct B { typedef bool Boolean; };
+
+template<int N>
+B<void>::Boolean concept vctb(!0);
+
+template<typename T>
+concept int vcti { 5 }; // expected-error {{declared type of variable concept must be 'bool'}}
+
+template<typename T>
+concept float vctf { 5.5 }; // expected-error {{declared type of variable concept must be 'bool'}}
+
+template<typename T>
+concept auto vcta { true }; // expected-error {{declared type of variable concept must be 'bool'}}
+
+template<typename T>
+concept decltype(auto) vctd { true }; // expected-error {{declared type of variable concept must be 'bool'}}
Index: test/CXX/concepts-ts/dcl.dcl/dcl.spec/dcl.spec.concept/p5.cpp
===================================================================
--- test/CXX/concepts-ts/dcl.dcl/dcl.spec/dcl.spec.concept/p5.cpp
+++ test/CXX/concepts-ts/dcl.dcl/dcl.spec/dcl.spec.concept/p5.cpp
@@ -11,3 +11,15 @@
 
 template<typename T>
 concept bool fcpva(...) { return true; } // expected-error {{function concept cannot have any parameters}}
+
+template<typename T>
+concept int fcrti() { return 5; } // expected-error {{declared return type of function concept must be 'bool'}}
+
+template<typename T>
+concept float fcrtf() { return 5.5; } // expected-error {{declared return type of function concept must be 'bool'}}
+
+template<typename T>
+concept auto fcrta(void) -> bool { return true; } // expected-error {{declared return type of function concept must be 'bool'}}
+
+template<typename T>
+concept decltype(auto) fcrtd(void) { return true; } // expected-error {{declared return type of function concept must be 'bool'}}
Index: lib/Sema/SemaDecl.cpp
===================================================================
--- lib/Sema/SemaDecl.cpp
+++ lib/Sema/SemaDecl.cpp
@@ -5986,6 +5986,17 @@
             << 0 << 3;
         NewVD->setInvalidDecl(true);
       }
+
+      // C++ Concepts TS [dcl.spec.concept]p6: A variable concept has the
+      // following restrictions:
+      // - The declared type shall have the type bool.
+      if (!R->isBooleanType()) {
+        SourceRange Range = D.getDeclSpec().getTypeSpecTypeLoc();
+        Diag(D.getIdentifierLoc(), diag::err_variable_concept_bool_decl)
+            << (Range.isValid() ? FixItHint::CreateReplacement(Range, "bool")
+                                : FixItHint());
+        NewVD->setInvalidDecl(true);
+      }
     }
   }
 
@@ -7668,6 +7679,18 @@
 
         // C++ Concepts TS [dcl.spec.concept]p5: A function concept has the
         // following restrictions:
+        // - The declared return type shall have the type bool.
+        if (!FPT->getReturnType()->isBooleanType() ||
+            D.getDeclSpec().containsPlaceholderType()) {
+          SourceRange Range = NewFD->getReturnTypeSourceRange();
+          Diag(D.getIdentifierLoc(), diag::err_function_concept_bool_ret)
+              << (Range.isValid() ? FixItHint::CreateReplacement(Range, "bool")
+                                  : FixItHint());
+          NewFD->setInvalidDecl();
+        }
+
+        // C++ Concepts TS [dcl.spec.concept]p5: A function concept has the
+        // following restrictions:
         // - The declaration's parameter list shall be equivalent to an empty
         //   parameter list.
         if (FPT->getNumParams() > 0 || FPT->isVariadic())
Index: include/clang/Basic/DiagnosticSemaKinds.td
===================================================================
--- include/clang/Basic/DiagnosticSemaKinds.td
+++ include/clang/Basic/DiagnosticSemaKinds.td
@@ -2067,6 +2067,10 @@
   "'%select{thread_local|inline|friend|constexpr}1'">;
 def err_function_concept_with_params : Error<
   "function concept cannot have any parameters">;
+def err_function_concept_bool_ret : Error<
+  "declared return type of function concept must be 'bool'">;
+def err_variable_concept_bool_decl : Error<
+  "declared type of variable concept must be 'bool'">;
 
 // C++11 char16_t/char32_t
 def warn_cxx98_compat_unicode_type : Warning<
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to