[clang] fe86dbb - [clang]: Remove assertion which checks explicit declaration

Richard Smith via cfe-commits cfe-commits at lists.llvm.org
Thu Aug 20 18:15:57 PDT 2020


Author: Gousemoodhin Nadaf
Date: 2020-08-20T18:15:43-07:00
New Revision: fe86dbb32da21e1c8c6eb4864a00f61ed3d003a3

URL: https://github.com/llvm/llvm-project/commit/fe86dbb32da21e1c8c6eb4864a00f61ed3d003a3
DIFF: https://github.com/llvm/llvm-project/commit/fe86dbb32da21e1c8c6eb4864a00f61ed3d003a3.diff

LOG: [clang]:  Remove assertion which checks explicit declaration

explicit keyword is declared outside of class is invalid, invalid explicit declaration is handled inside DiagnoseFunctionSpecifiers() function. To avoid compiler crash in case of invalid explicit declaration, remove assertion.

Reviewed By: rsmith

Differential Revision: https://reviews.llvm.org/D83929

Added: 
    clang/test/Misc/explicit.cpp

Modified: 
    clang/lib/Sema/DeclSpec.cpp

Removed: 
    


################################################################################
diff  --git a/clang/lib/Sema/DeclSpec.cpp b/clang/lib/Sema/DeclSpec.cpp
index f553b5ca6079..a3f770bb00ad 100644
--- a/clang/lib/Sema/DeclSpec.cpp
+++ b/clang/lib/Sema/DeclSpec.cpp
@@ -1014,9 +1014,6 @@ bool DeclSpec::setFunctionSpecExplicit(SourceLocation Loc,
                                        const char *&PrevSpec, unsigned &DiagID,
                                        ExplicitSpecifier ExplicitSpec,
                                        SourceLocation CloseParenLoc) {
-  assert((ExplicitSpec.getKind() == ExplicitSpecKind::ResolvedTrue ||
-          ExplicitSpec.getExpr()) &&
-         "invalid ExplicitSpecifier");
   // 'explicit explicit' is ok, but warn as this is likely not what the user
   // intended.
   if (hasExplicitSpecifier()) {

diff  --git a/clang/test/Misc/explicit.cpp b/clang/test/Misc/explicit.cpp
new file mode 100644
index 000000000000..b544fc437f05
--- /dev/null
+++ b/clang/test/Misc/explicit.cpp
@@ -0,0 +1,9 @@
+// RUN: %clang_cc1 -std=c++20 %s -verify
+
+int foo ()  {
+  int b;
+  explicit( && b );  // expected-error{{conversion from 'void *' to 'bool' is not allowed in a converted constant expression}}
+                     // expected-error at -1{{'explicit' can only appear on non-static member functions}}
+                     // expected-error at -2{{use of undeclared label 'b'}}
+                     // expected-warning at -3{{declaration does not declare anything}}
+}


        


More information about the cfe-commits mailing list