This is an archive of the discontinued LLVM Phabricator instance.

[NFC] Fix builds on recent GCC with C++20 enabled
ClosedPublic

Authored by alexbatashev on Jul 9 2023, 1:55 AM.

Details

Summary

The following pattern fails on recent GCC versions with -std=c++20 flag passed
and succeeds with -std=c++17. Such behavior is not observed on Clang 16.0.

c++
template <typename T>
struct Foo {
    Foo<T>(int a) {}
};

This patch removes template parameter from constructor in two occurences to
make the following command complete successfully:
bazel build -c fastbuild --cxxopt=-std=c++20 --host_cxxopt=-std=c++20 @llvm-project//llvm/...

Diff Detail

Event Timeline

alexbatashev created this revision.Jul 9 2023, 1:55 AM
Herald added a project: Restricted Project. · View Herald TranscriptJul 9 2023, 1:55 AM
alexbatashev requested review of this revision.Jul 9 2023, 1:55 AM
Herald added a reviewer: sstefan1. · View Herald Transcript
Herald added a project: Restricted Project. · View Herald Transcript

A brief note for reviewers. This appears to be a bug in either Clang or GCC. Briefly looking at recent C++ defect reports, I couldn't find anything like this. So, I lean towards a bug in GCC 12 and 13 (I didn't check other versions). But if someone knows what the rootcause is, please, let me know.
A link to Compiler Explorer with the reproducer to play around: https://godbolt.org/z/1fKqdfnrM

jdoerfert added inline comments.Jul 9 2023, 1:19 PM
llvm/lib/Transforms/IPO/AttributorAttributes.cpp
3475

This part LGTM.

arsenm accepted this revision.Jul 17 2023, 2:37 AM
This revision is now accepted and ready to land.Jul 17 2023, 2:37 AM
This revision was landed with ongoing or failed builds.Jul 18 2023, 9:45 AM
This revision was automatically updated to reflect the committed changes.

Thanks for fixing it! I also discovered it today... I think this is according to the standard: https://eel.is/c++draft/diff.cpp17.class#2 I guess Clang should warn about this; and GCC's error message isn't helpful at all (since version 11 btw)

Thanks for fixing it! I also discovered it today... I think this is according to the standard: https://eel.is/c++draft/diff.cpp17.class#2 I guess Clang should warn about this; and GCC's error message isn't helpful at all (since version 11 btw)

Totally agree. Did you already submit bugs to both projects?

Thanks for fixing it! I also discovered it today... I think this is according to the standard: https://eel.is/c++draft/diff.cpp17.class#2 I guess Clang should warn about this; and GCC's error message isn't helpful at all (since version 11 btw)

Totally agree. Did you already submit bugs to both projects?

No, didn't get to it yet. I didn't realize at first that Clang just silently accepts it...

@tstellar also FYI. I know that there are no more point releases planned for 16.0, but the fix in llvm/lib/Transforms/IPO/AttributorAttributes.cpp also affects GCC + C++20 builds of release/16.x. If there ever is another release of 16.0, this one would be great to include :)