From f4cd8f4ece29e28e0d503b105432b5b4a1dc4519 Mon Sep 17 00:00:00 2001 From: Douglas Gregor Date: Mon, 19 Apr 2010 22:34:40 +0000 Subject: Only suppress the "extern variable has an initializer" warning when the extern entity being initialized is const. llvm-svn: 101821 --- clang/lib/Sema/SemaDecl.cpp | 2 +- clang/test/SemaCXX/storage-class.cpp | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) (limited to 'clang') diff --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp index 045b3e8c381..115b7bf756e 100644 --- a/clang/lib/Sema/SemaDecl.cpp +++ b/clang/lib/Sema/SemaDecl.cpp @@ -3819,7 +3819,7 @@ void Sema::AddInitializerToDecl(DeclPtrTy dcl, ExprArg init, bool DirectInit) { } } else if (VDecl->isFileVarDecl()) { if (VDecl->getStorageClass() == VarDecl::Extern && - !getLangOptions().CPlusPlus) + (!getLangOptions().CPlusPlus || !VDecl->getType().isConstQualified())) Diag(VDecl->getLocation(), diag::warn_extern_init); if (!VDecl->isInvalidDecl()) { InitializationSequence InitSeq(*this, Entity, Kind, &Init, 1); diff --git a/clang/test/SemaCXX/storage-class.cpp b/clang/test/SemaCXX/storage-class.cpp index a31e67be7e4..4025595de12 100644 --- a/clang/test/SemaCXX/storage-class.cpp +++ b/clang/test/SemaCXX/storage-class.cpp @@ -1,2 +1,3 @@ // RUN: %clang_cc1 -fsyntax-only -verify %s -extern const int PR6495 = 42; +extern const int PR6495a = 42; +extern int PR6495b = 42; // expected-warning{{'extern' variable has an initializer}} -- cgit v1.2.3