[cfe-commits] r72664 - in /cfe/trunk: include/clang/Basic/DiagnosticSemaKinds.td include/clang/Parse/DeclSpec.h lib/Parse/DeclSpec.cpp lib/Parse/ParseDecl.cpp lib/Parse/ParseExpr.cpp lib/Sema/SemaDecl.cpp lib/Sema/SemaType.cpp test/SemaCXX/exception-spec.cpp

Sebastian Redl sebastian.redl at getdesigned.at
Sun May 31 04:47:31 PDT 2009


Author: cornedbee
Date: Sun May 31 06:47:27 2009
New Revision: 72664

URL: http://llvm.org/viewvc/llvm-project?rev=72664&view=rev
Log:
Disallow exception specs on typedefs.

Modified:
    cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
    cfe/trunk/include/clang/Parse/DeclSpec.h
    cfe/trunk/lib/Parse/DeclSpec.cpp
    cfe/trunk/lib/Parse/ParseDecl.cpp
    cfe/trunk/lib/Parse/ParseExpr.cpp
    cfe/trunk/lib/Sema/SemaDecl.cpp
    cfe/trunk/lib/Sema/SemaType.cpp
    cfe/trunk/test/SemaCXX/exception-spec.cpp

Modified: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td?rev=72664&r1=72663&r2=72664&view=diff

==============================================================================
--- cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td Sun May 31 06:47:27 2009
@@ -269,12 +269,14 @@
   "deleted definition must be first declaration">;
 
 // C++ exception specifications
+def err_exception_spec_in_typedef : Error<
+  "exception specifications are not allowed in typedefs">;
 def err_distant_exception_spec : Error<
   "exception specifications are not allowed beyond a single level "
   "of indirection">;
 def err_incomplete_in_exception_spec : Error<
-  "%select{|pointer to |member pointer to |reference to }1incomplete type %0 "
-  "is not allowed in exception specification">;
+  "%select{|pointer to |reference to }1incomplete type %0 is not allowed "
+  "in exception specification">;
 
 // C++ access checking
 def err_class_redeclared_with_different_access : Error<

Modified: cfe/trunk/include/clang/Parse/DeclSpec.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Parse/DeclSpec.h?rev=72664&r1=72663&r2=72664&view=diff

==============================================================================
--- cfe/trunk/include/clang/Parse/DeclSpec.h (original)
+++ cfe/trunk/include/clang/Parse/DeclSpec.h Sun May 31 06:47:27 2009
@@ -559,6 +559,10 @@
     /// the function has one.
     unsigned NumExceptions;
 
+    /// ThrowLoc - When hasExceptionSpec is true, the location of the throw
+    /// keyword introducing the spec.
+    unsigned ThrowLoc;
+
     /// ArgInfo - This is a pointer to a new[]'d array of ParamInfo objects that
     /// describe the arguments for this function declarator.  This is null if
     /// there are no arguments specified.
@@ -588,6 +592,9 @@
     SourceLocation getEllipsisLoc() const {
       return SourceLocation::getFromRawEncoding(EllipsisLoc);
     }
+    SourceLocation getThrowLoc() const {
+      return SourceLocation::getFromRawEncoding(ThrowLoc);
+    }
   };
 
   struct BlockPointerTypeInfo {
@@ -704,6 +711,7 @@
                                      SourceLocation EllipsisLoc,
                                      ParamInfo *ArgInfo, unsigned NumArgs,
                                      unsigned TypeQuals, bool hasExceptionSpec,
+                                     SourceLocation ThrowLoc,
                                      bool hasAnyExceptionSpec,
                                      ActionBase::TypeTy **Exceptions,
                                      SourceRange *ExceptionRanges,

Modified: cfe/trunk/lib/Parse/DeclSpec.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Parse/DeclSpec.cpp?rev=72664&r1=72663&r2=72664&view=diff

==============================================================================
--- cfe/trunk/lib/Parse/DeclSpec.cpp (original)
+++ cfe/trunk/lib/Parse/DeclSpec.cpp Sun May 31 06:47:27 2009
@@ -33,6 +33,7 @@
                                              unsigned NumArgs,
                                              unsigned TypeQuals,
                                              bool hasExceptionSpec,
+                                             SourceLocation ThrowLoc,
                                              bool hasAnyExceptionSpec,
                                              ActionBase::TypeTy **Exceptions,
                                              SourceRange *ExceptionRanges,
@@ -50,6 +51,7 @@
   I.Fun.NumArgs          = NumArgs;
   I.Fun.ArgInfo          = 0;
   I.Fun.hasExceptionSpec = hasExceptionSpec;
+  I.Fun.ThrowLoc         = ThrowLoc.getRawEncoding();
   I.Fun.hasAnyExceptionSpec = hasAnyExceptionSpec;
   I.Fun.NumExceptions    = NumExceptions;
   I.Fun.Exceptions       = 0;

Modified: cfe/trunk/lib/Parse/ParseDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Parse/ParseDecl.cpp?rev=72664&r1=72663&r2=72664&view=diff

==============================================================================
--- cfe/trunk/lib/Parse/ParseDecl.cpp (original)
+++ cfe/trunk/lib/Parse/ParseDecl.cpp Sun May 31 06:47:27 2009
@@ -2274,6 +2274,7 @@
     // cv-qualifier-seq[opt].
     DeclSpec DS;
     bool hasExceptionSpec = false;
+    SourceLocation ThrowLoc;
     bool hasAnyExceptionSpec = false;
     llvm::SmallVector<TypeTy*, 2> Exceptions;
     llvm::SmallVector<SourceRange, 2> ExceptionRanges;
@@ -2285,6 +2286,7 @@
       // Parse exception-specification[opt].
       if (Tok.is(tok::kw_throw)) {
         hasExceptionSpec = true;
+        ThrowLoc = Tok.getLocation();
         ParseExceptionSpecification(Loc, Exceptions, ExceptionRanges,
                                     hasAnyExceptionSpec);
         assert(Exceptions.size() == ExceptionRanges.size() &&
@@ -2299,7 +2301,7 @@
                                                SourceLocation(),
                                                /*arglist*/ 0, 0,
                                                DS.getTypeQualifiers(),
-                                               hasExceptionSpec,
+                                               hasExceptionSpec, ThrowLoc,
                                                hasAnyExceptionSpec,
                                                Exceptions.data(),
                                                ExceptionRanges.data(),
@@ -2448,6 +2450,7 @@
 
   DeclSpec DS;
   bool hasExceptionSpec = false;
+  SourceLocation ThrowLoc;
   bool hasAnyExceptionSpec = false;
   llvm::SmallVector<TypeTy*, 2> Exceptions;
   llvm::SmallVector<SourceRange, 2> ExceptionRanges;
@@ -2460,6 +2463,7 @@
     // Parse exception-specification[opt].
     if (Tok.is(tok::kw_throw)) {
       hasExceptionSpec = true;
+      ThrowLoc = Tok.getLocation();
       ParseExceptionSpecification(Loc, Exceptions, ExceptionRanges,
                                   hasAnyExceptionSpec);
       assert(Exceptions.size() == ExceptionRanges.size() &&
@@ -2472,7 +2476,7 @@
                                              EllipsisLoc,
                                              ParamInfo.data(), ParamInfo.size(),
                                              DS.getTypeQualifiers(),
-                                             hasExceptionSpec,
+                                             hasExceptionSpec, ThrowLoc,
                                              hasAnyExceptionSpec,
                                              Exceptions.data(),
                                              ExceptionRanges.data(),
@@ -2551,7 +2555,8 @@
                                              SourceLocation(),
                                              &ParamInfo[0], ParamInfo.size(),
                                              /*TypeQuals*/0,
-                                             /*exception*/false, false, 0, 0, 0,
+                                             /*exception*/false,
+                                             SourceLocation(), false, 0, 0, 0,
                                              LParenLoc, D),
                 RLoc);
 }

Modified: cfe/trunk/lib/Parse/ParseExpr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Parse/ParseExpr.cpp?rev=72664&r1=72663&r2=72664&view=diff

==============================================================================
--- cfe/trunk/lib/Parse/ParseExpr.cpp (original)
+++ cfe/trunk/lib/Parse/ParseExpr.cpp Sun May 31 06:47:27 2009
@@ -1481,7 +1481,8 @@
     ParamInfo.AddTypeInfo(DeclaratorChunk::getFunction(true, false, 
                                                        SourceLocation(),
                                                        0, 0, 0,
-                                                       false, false, 0, 0, 0,
+                                                       false, SourceLocation(),
+                                                       false, 0, 0, 0,
                                                        CaretLoc, ParamInfo),
                           CaretLoc);
 

Modified: cfe/trunk/lib/Sema/SemaDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDecl.cpp?rev=72664&r1=72663&r2=72664&view=diff

==============================================================================
--- cfe/trunk/lib/Sema/SemaDecl.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDecl.cpp Sun May 31 06:47:27 2009
@@ -3164,7 +3164,8 @@
   assert(!Error && "Error setting up implicit decl!");
   Declarator D(DS, Declarator::BlockContext);
   D.AddTypeInfo(DeclaratorChunk::getFunction(false, false, SourceLocation(), 0,
-                                             0, 0, false, false, 0,0,0, Loc, D),
+                                             0, 0, false, SourceLocation(),
+                                             false, 0,0,0, Loc, D),
                 SourceLocation());
   D.SetIdentifier(&II, Loc);
 

Modified: cfe/trunk/lib/Sema/SemaType.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaType.cpp?rev=72664&r1=72663&r2=72664&view=diff

==============================================================================
--- cfe/trunk/lib/Sema/SemaType.cpp (original)
+++ cfe/trunk/lib/Sema/SemaType.cpp Sun May 31 06:47:27 2009
@@ -737,7 +737,7 @@
       // does not have a K&R-style identifier list), then the arguments are part
       // of the type, otherwise the argument list is ().
       const DeclaratorChunk::FunctionTypeInfo &FTI = DeclType.Fun;
-      
+
       // C99 6.7.5.3p1: The return type may not be a function or array type.
       if (T->isArrayType() || T->isFunctionType()) {
         Diag(DeclType.Loc, diag::err_func_returning_array_function) << T;
@@ -754,6 +754,12 @@
             << Context.getTypeDeclType(Tag);
       }
 
+      // Exception specs are not allowed in typedefs. Complain, but add it
+      // anyway.
+      if (FTI.hasExceptionSpec &&
+          D.getDeclSpec().getStorageClassSpec() == DeclSpec::SCS_typedef)
+        Diag(FTI.getThrowLoc(), diag::err_exception_spec_in_typedef);
+
       if (FTI.NumArgs == 0) {
         if (getLangOptions().CPlusPlus) {
           // C++ 8.3.5p2: If the parameter-declaration-clause is empty, the
@@ -978,17 +984,13 @@
   // C++ 15.4p2: A type denoted in an exception-specification shall not denote
   //   an incomplete type a pointer or reference to an incomplete type, other
   //   than (cv) void*.
-  // The standard does not mention member pointers, but it has to mean them too.
   int kind;
   if (const PointerType* IT = T->getAsPointerType()) {
     T = IT->getPointeeType();
     kind = 1;
-  } else if (const MemberPointerType* IT = T->getAsMemberPointerType()) {
-    T = IT->getPointeeType();
-    kind = 2;
   } else if (const ReferenceType* IT = T->getAsReferenceType()) {
     T = IT->getPointeeType();
-    kind = 3;
+    kind = 2;
   } else
     return false;
 

Modified: cfe/trunk/test/SemaCXX/exception-spec.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/exception-spec.cpp?rev=72664&r1=72663&r2=72664&view=diff

==============================================================================
--- cfe/trunk/test/SemaCXX/exception-spec.cpp (original)
+++ cfe/trunk/test/SemaCXX/exception-spec.cpp Sun May 31 06:47:27 2009
@@ -8,7 +8,7 @@
 // Function taking reference to function with spec
 void g(void pfa() throw(int));
 // Typedef for pointer to function with spec
-typedef int (*pf)() throw(int); // xpected-error spec-on-typedef
+typedef int (*pf)() throw(int); // expected-error {{specifications are not allowed in typedefs}}
 
 // Some more:
 // Function returning function with spec





More information about the cfe-commits mailing list