From: Sebastian Redl Date: Wed, 8 Sep 2010 04:46:19 +0000 (+0000) Subject: Don't give 'global constructor' warnings for function statics, even if they have... X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=36281c6fd792a254ade72caf825bad7b7c63b0e0;p=clang Don't give 'global constructor' warnings for function statics, even if they have a direct initializer. Fixes PR8095. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@113344 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Sema/SemaDeclCXX.cpp b/lib/Sema/SemaDeclCXX.cpp index 63acdb5f1c..7205abdbc2 100644 --- a/lib/Sema/SemaDeclCXX.cpp +++ b/lib/Sema/SemaDeclCXX.cpp @@ -5622,7 +5622,7 @@ void Sema::AddCXXDirectInitializerToDecl(Decl *RealDecl, if (!VDecl->isInvalidDecl() && !VDecl->getDeclContext()->isDependentContext() && - VDecl->hasGlobalStorage() && + VDecl->hasGlobalStorage() && !VDecl->isStaticLocal() && !VDecl->getInit()->isConstantInitializer(Context, VDecl->getType()->isReferenceType())) Diag(VDecl->getLocation(), diag::warn_global_constructor) diff --git a/test/SemaCXX/warn-global-constructors.cpp b/test/SemaCXX/warn-global-constructors.cpp index 107bbe129f..e14117eaf3 100644 --- a/test/SemaCXX/warn-global-constructors.cpp +++ b/test/SemaCXX/warn-global-constructors.cpp @@ -77,5 +77,15 @@ namespace test6 { void f2() { static A& a = *new A; } +} + +namespace pr8095 { + struct Foo { + int x; + Foo(int x1) : x(x1) {} + }; -} \ No newline at end of file + void bar() { + static Foo a(0); + } +}