This is an archive of the discontinued LLVM Phabricator instance.

Fix the build with gcc 8.x when `-Wredundant-decls` is passed
ClosedPublic

Authored by dim on Feb 19 2019, 8:21 PM.

Details

Summary

gcc 8.x fails claiming that __throw_runtime_error, defined in __locale and
stdexcept, are both defined in the std namespace if -Wredundant-decls
is passed on the command line; this is the case with FreeBSD when
${WARNS} == 6.

Doing some closer inspection, it seems that it was declared in both
headers, but only implemented in locale.cpp. As such, the appropriate
location for the definition is further up in __locale [1].

  1. Just removing the stdexcept definition didn't work; it needed to be moved up so earlier uses of the definition wouldn't cause the compiler to error out.

Signed-off-by: Enji Cooper <yaneurabeya@gmail.com>

Diff Detail

Repository
rL LLVM

Event Timeline

ngie created this revision.Feb 19 2019, 8:21 PM
ngie added a reviewer: Restricted Project.Feb 19 2019, 8:23 PM
ngie removed reviewers: emaste, dim.
ngie added subscribers: dim, emaste, brooks.
ngie edited reviewers, added: kuhar, kristina, MaskRay; removed: Restricted Project.Feb 19 2019, 8:27 PM
kuhar removed a reviewer: kuhar.Feb 19 2019, 8:29 PM
ngie edited the summary of this revision. (Show Details)Feb 19 2019, 9:43 PM
ngie retitled this revision from Fix the build with gcc 8.x to Fix the build with gcc 8.x when `-Wredundant-decls` is passed.Feb 19 2019, 9:44 PM

but this isn't redundant... as evidenced by the fact there is green in this patch .

EricWF accepted this revision.Feb 19 2019, 11:17 PM

I'm fine with this. But it's a bogus warning

This revision is now accepted and ready to land.Feb 19 2019, 11:17 PM
ngie added a comment.Feb 19 2019, 11:18 PM

but this isn't redundant... as evidenced by the fact there is green in this patch .

There are many instances that I've run into where clang doesn't have issues with redundant definitions, compared to gcc. gcc whines if you define things multiple times, even if the definitions are the same :(.

These aren't definitions. They're declarations. And the warning or broken. We should turn it off not fix it

ngie added a comment.EditedFeb 19 2019, 11:24 PM

These aren't definitions. They're declarations.

You're correct. I meant declaration, not definition.

And the warning or broken. We should turn it off not fix it

Unfortunately, things like these aren't necessarily within the control of the llvm project. FreeBSD (for instance) uses its own make infrastructure/flags. In order to catch issues like this (which are valid elsewhere in code) we enable this warning.

Not being able to compile with this warning on gcc is very unfortunate and means we lose out on potentially good coverage/signal (especially in global/standard headers, like this).

Going back and retroactively fixing gcc compilers isn't necessarily possible either. We need to bootstrap newer toolchains (for instance) with buggy-ish toolchains from time to time.

dim added a comment.Feb 20 2019, 4:02 AM

In the case of <__locale>, __throw_runtime_error is already used in the file before its declaration, but via transitive includes, <stdexcept> is also included earlier, so it gets the duplicate declaration of __throw_runtime_error from there. I think we can just delete the __throw_runtime_error declaration from <__locale> altogether.

I also have a few other gcc specific warning fixes lined up, will submit those in another review.

dim commandeered this revision.Feb 20 2019, 12:55 PM
dim added a reviewer: ngie.

I will update and commit.

This revision was automatically updated to reflect the committed changes.
Herald added a project: Restricted Project. · View Herald TranscriptFeb 20 2019, 1:01 PM
ngie added a comment.Feb 20 2019, 7:18 PM
In D58425#1404742, @dim wrote:

I will update and commit.

Sounds good -- thank you @dim!