[cfe-commits] r64686 - in /cfe/trunk: include/clang/Basic/DiagnosticSemaKinds.def lib/Sema/SemaType.cpp test/Parser/cxx-template-decl.cpp test/SemaCXX/implicit-int.cpp

Douglas Gregor dgregor at apple.com
Mon Feb 16 14:38:20 PST 2009


Author: dgregor
Date: Mon Feb 16 16:38:20 2009
New Revision: 64686

URL: http://llvm.org/viewvc/llvm-project?rev=64686&view=rev
Log:
Make "implicit int" an error in C++ (unless we're allowing Microsoft
extensions). This caught a couple bugs in our test suite :)

Added:
    cfe/trunk/test/SemaCXX/implicit-int.cpp
Modified:
    cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.def
    cfe/trunk/lib/Sema/SemaType.cpp
    cfe/trunk/test/Parser/cxx-template-decl.cpp

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

==============================================================================
--- cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.def (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.def Mon Feb 16 16:38:20 2009
@@ -1375,6 +1375,8 @@
      "declaration specifier missing, defaulting to 'int'")
 DIAG(ext_missing_type_specifier, EXTENSION,
      "type specifier missing, defaults to 'int'")
+DIAG(err_missing_type_specifier, ERROR,
+     "C++ requires a type specifier for all declarations")
 DIAG(warn_objc_array_of_interfaces, WARNING,
      "array of interface %0 should probably be an array of pointers")
 DIAG(ext_c99_array_usage, EXTENSION,

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

==============================================================================
--- cfe/trunk/lib/Sema/SemaType.cpp (original)
+++ cfe/trunk/lib/Sema/SemaType.cpp Mon Feb 16 16:38:20 2009
@@ -79,14 +79,16 @@
                                        DeclSpec::PQ_TypeSpecifier |
                                        DeclSpec::PQ_TypeQualifier)) == 0)
         Diag(DS.getSourceRange().getBegin(), diag::ext_missing_declspec);
-    } else {
+    } else if (!DS.hasTypeSpecifier()) {
       // C99 and C++ require a type specifier.  For example, C99 6.7.2p2 says:
       // "At least one type specifier shall be given in the declaration
       // specifiers in each declaration, and in the specifier-qualifier list in
       // each struct declaration and type name."
-      // FIXME: this should be a hard error in C++
-      if (!DS.hasTypeSpecifier())
-        Diag(DS.getSourceRange().getBegin(), diag::ext_missing_type_specifier);
+      // FIXME: Does Microsoft really have the implicit int extension in C++?
+      unsigned DK = getLangOptions().CPlusPlus && !getLangOptions().Microsoft?
+          diag::err_missing_type_specifier
+        : diag::ext_missing_type_specifier;
+      Diag(DS.getSourceRange().getBegin(), DK);
     }
       
     // FALL THROUGH.  

Modified: cfe/trunk/test/Parser/cxx-template-decl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Parser/cxx-template-decl.cpp?rev=64686&r1=64685&r2=64686&view=diff

==============================================================================
--- cfe/trunk/test/Parser/cxx-template-decl.cpp (original)
+++ cfe/trunk/test/Parser/cxx-template-decl.cpp Mon Feb 16 16:38:20 2009
@@ -2,9 +2,11 @@
 
 // Errors
 export class foo { };   // expected-error {{expected template}}
-template  x;            // expected-error {{expected '<' after 'template'}}
+template  x;            // expected-error {{expected '<' after 'template'}} \
+// expected-error {{C++ requires a type specifier for all declarations}}
 export template x;      // expected-error {{expected '<' after 'template'}} \
-                        // expected-note {{exported templates are unsupported}}
+                        // expected-note {{exported templates are unsupported}} \
+// expected-error {{C++ requires a type specifier for all declarations}}
 // See Sema::ParsedFreeStandingDeclSpec about the double diagnostic. This is
 // because ParseNonTypeTemplateParameter starts parsing a DeclSpec.
 template < ;            // expected-error {{parse error}} expected-error {{declaration does not declare anything}}
@@ -26,8 +28,8 @@
 template <typename, typename> struct D;
 
 // Forward declarations with default parameters?
-template <typename T = int> X1;
-template <typename = int> X2;
+template <typename T = int> class X1;
+template <typename = int> class X2;
 
 // Forward declarations w/template template parameters
 template <template <typename> class T> class TTP1;
@@ -41,10 +43,10 @@
 template <int N> class NTP1;
 template <int N = 5> class NTP2;
 template <int = 10> class NTP3;
-template <unsigned int N = 12u> NTP4;;
-template <unsigned int = 12u> NTP5;
-template <unsigned = 15u> NTP6;
-template <typename T, T Obj> NTP7;
+template <unsigned int N = 12u> class NTP4; 
+template <unsigned int = 12u> class NTP5;
+template <unsigned = 15u> class NTP6;
+template <typename T, T Obj> class NTP7;
 
 // Template class declarations
 template <typename T> struct A { };

Added: cfe/trunk/test/SemaCXX/implicit-int.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/implicit-int.cpp?rev=64686&view=auto

==============================================================================
--- cfe/trunk/test/SemaCXX/implicit-int.cpp (added)
+++ cfe/trunk/test/SemaCXX/implicit-int.cpp Mon Feb 16 16:38:20 2009
@@ -0,0 +1,5 @@
+// RUN: clang -fsyntax-only -verify %s
+
+x; // expected-error{{C++ requires a type specifier for all declarations}}
+
+f(int y) { return y; } // expected-error{{C++ requires a type specifier for all declarations}}





More information about the cfe-commits mailing list