[cfe-commits] r45188 - in /cfe/trunk: Sema/SemaType.cpp include/clang/Basic/DiagnosticKinds.def test/Sema/declspec.c

Chris Lattner sabre at nondot.org
Tue Dec 18 21:31:29 PST 2007


Author: lattner
Date: Tue Dec 18 23:31:29 2007
New Revision: 45188

URL: http://llvm.org/viewvc/llvm-project?rev=45188&view=rev
Log:
Implement C99 6.7.5.3p1

Added:
    cfe/trunk/test/Sema/declspec.c
Modified:
    cfe/trunk/Sema/SemaType.cpp
    cfe/trunk/include/clang/Basic/DiagnosticKinds.def

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

==============================================================================
--- cfe/trunk/Sema/SemaType.cpp (original)
+++ cfe/trunk/Sema/SemaType.cpp Tue Dec 18 23:31:29 2007
@@ -262,6 +262,15 @@
       // 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.getAsString());
+        T = Context.IntTy;
+        D.setInvalidType(true);
+      }
+        
       if (!FTI.hasPrototype) {
         // Simple void foo(), where the incoming T is the result type.
         T = Context.getFunctionTypeNoProto(T);

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

==============================================================================
--- cfe/trunk/include/clang/Basic/DiagnosticKinds.def (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticKinds.def Tue Dec 18 23:31:29 2007
@@ -644,6 +644,8 @@
 DIAG(ext_implicit_function_decl, EXTENSION,
      "implicit declaration of function '%0' is invalid in C99")
 
+DIAG(err_func_returning_array_function, ERROR,
+     "function cannot return array or function type '%0'")
 DIAG(err_field_declared_as_function, ERROR,
      "field '%0' declared as a function")
 DIAG(err_field_incomplete, ERROR,

Added: cfe/trunk/test/Sema/declspec.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/declspec.c?rev=45188&view=auto

==============================================================================
--- cfe/trunk/test/Sema/declspec.c (added)
+++ cfe/trunk/test/Sema/declspec.c Tue Dec 18 23:31:29 2007
@@ -0,0 +1,5 @@
+// RUN: clang %s -verify -fsyntax-only
+typedef char T[4];
+
+T foo(int n, int m) {  }  // expected-error {{cannot return array or function}}
+





More information about the cfe-commits mailing list