Skip to content

-Wglobal-constructors false positive #8467

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
llvmbot opened this issue Sep 7, 2010 · 7 comments
Closed

-Wglobal-constructors false positive #8467

llvmbot opened this issue Sep 7, 2010 · 7 comments
Labels
bugzilla Issues migrated from bugzilla c++

Comments

@llvmbot
Copy link
Member

llvmbot commented Sep 7, 2010

Bugzilla Link 8095
Resolution FIXED
Resolved on Sep 18, 2010 00:26
Version trunk
OS Linux
Reporter LLVM Bugzilla Contributor
CC @DougGregor,@rjmccall

Extended Description

The following example gives a warning when -Wglobal-constructors is enabled:

struct Foo {
int x;
Foo(int x1) : x(x1) {}
};

void bar() {
static Foo a(0);
}


clang++ output:

a.cpp:8:13: warning: declaration requires a global constructor [-Wglobal-constructors]
static Foo a(0);
^~~

@lattner
Copy link
Collaborator

lattner commented Sep 7, 2010

That does require a static constructor. When the optimizer is turned on, sometimes it can remove them, but it certainly does at -O0.

@lattner
Copy link
Collaborator

lattner commented Sep 7, 2010

Ah, no, you're right, it's a static in a function, so it is lazily constructed.

@llvmbot
Copy link
Member Author

llvmbot commented Sep 8, 2010

Fixed in r113344.

@llvmbot
Copy link
Member Author

llvmbot commented Sep 17, 2010

When adding a "~Foo() {}" destructor I'm getting also a "global destructor" warning. Is it correct?

@rjmccall
Copy link
Contributor

When adding a "~Foo() {}" destructor I'm getting also a "global destructor"
warning. Is it correct?

What platform are you on? On some platforms, those do require (conditionalized) global destructors.

@llvmbot
Copy link
Member Author

llvmbot commented Sep 17, 2010

x86_64 GNU/Linux

@rjmccall
Copy link
Contributor

Apparently we don't actually pay attention to that. I've disabled the global-destructor warning on static locals for all targets (in r114269) and filed llvm/llvm-bugzilla-archive#8176 to track the target-specific fix.

@llvmbot llvmbot transferred this issue from llvm/llvm-bugzilla-archive Dec 3, 2021
augusto2112 pushed a commit to augusto2112/llvm-project that referenced this issue Mar 25, 2024
[next][llvm] use new noncopyable infrastructure
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bugzilla Issues migrated from bugzilla c++
Projects
None yet
Development

No branches or pull requests

3 participants