From: Chris Lattner Date: Tue, 28 Aug 2007 16:40:32 +0000 (+0000) Subject: warn about long long when in c89 mode. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=b23deda7333cfc2316c989d10745c145dfbea6d6;p=clang warn about long long when in c89 mode. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@41543 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/Sema/SemaType.cpp b/Sema/SemaType.cpp index 17ab64a196..bbf8457acf 100644 --- a/Sema/SemaType.cpp +++ b/Sema/SemaType.cpp @@ -16,6 +16,7 @@ #include "clang/AST/Decl.h" #include "clang/Parse/DeclSpec.h" #include "clang/Lex/IdentifierTable.h" +#include "clang/Basic/LangOptions.h" using namespace clang; /// ConvertDeclSpecToType - Convert the specified declspec to the appropriate @@ -122,6 +123,11 @@ static QualType ConvertDeclSpecToType(const DeclSpec &DS, ASTContext &Ctx) { /// GetTypeForDeclarator - Convert the type for the specified declarator to Type /// instances. QualType Sema::GetTypeForDeclarator(Declarator &D, Scope *S) { + // long long is a C99 feature. + if (!getLangOptions().C99 && + D.getDeclSpec().getTypeSpecWidth() == DeclSpec::TSW_longlong) + Diag(D.getDeclSpec().getTypeSpecWidthLoc(), diag::ext_longlong); + QualType T = ConvertDeclSpecToType(D.getDeclSpec(), Context); // Apply const/volatile/restrict qualifiers to T. diff --git a/include/clang/Basic/DiagnosticKinds.def b/include/clang/Basic/DiagnosticKinds.def index e8b4dab25b..dbf1b270a0 100644 --- a/include/clang/Basic/DiagnosticKinds.def +++ b/include/clang/Basic/DiagnosticKinds.def @@ -438,6 +438,8 @@ DIAG(err_invalid_long_spec, ERROR, "'long %0' is invalid") DIAG(err_invalid_longlong_spec, ERROR, "'long long %0' is invalid") +DIAG(ext_longlong, EXTENSION, + "'long long' is an extension when C99 mode is not enabled") DIAG(err_invalid_complex_spec, ERROR, "'_Complex %0' is invalid") DIAG(err_invalid_thread_spec, ERROR, diff --git a/test/Sema/c89.c b/test/Sema/c89.c index 57085db644..a78472222a 100644 --- a/test/Sema/c89.c +++ b/test/Sema/c89.c @@ -17,3 +17,6 @@ void foo() { __extension__ int j; /* expected-warning {{mixing declarations and code}} */ } } + +long long x; /* expected-warning {{extension}} */ +