-
Notifications
You must be signed in to change notification settings - Fork 13.3k
[clang] add -fimplicit-constexpr
flag
#136436
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
Open
hanickadot
wants to merge
7
commits into
llvm:main
Choose a base branch
from
hanickadot:feature/implicit-constexpr-flag
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
f37eb75
[clang] add -fimplicit-constexpr flag (with same behaviour as GCC)
hanickadot a486edc
[clang] `-fimplicit-constexpr` release notes.
hanickadot 0062163
[clang] `-fimplicit-constexpr` fix test (forgot to push fixed version…
hanickadot 5f388d0
[clang] add -fimplicit-constexpr flag (for new constexpr interpret)
hanickadot cdae12c
[clang] add -fimplicit-constexpr flag: add one more test
hanickadot 2c47041
[clang] add -fimplicit-constexpr flag: fix failed tests (I wish we ha…
hanickadot 009dbf9
[clang] add -fimplicit-constexpr flag: fix failed tests
hanickadot File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,117 @@ | ||
|
||
// RUN: %clang_cc1 -verify=ALL_NORMAL,NORMAL14,BOTH14,ALL_PRE20,ALLNORMAL,NORMAL_PRE20,ALL -std=c++14 %s | ||
// RUN: %clang_cc1 -verify=IMPLICIT14,IMPLICIT_PRE20,BOTH14,ALL_PRE20,ALLIMPLICIT,ALLIMPLICITOLD,ALL -fimplicit-constexpr -std=c++14 %s | ||
// RUN: %clang_cc1 -verify=IMPLICIT14,IMPLICIT_PRE20,BOTH14,ALL_PRE20,ALLIMPLICIT,ALLIMPLICITNEW,ALL -fimplicit-constexpr -std=c++14 %s -fexperimental-new-constant-interpreter | ||
|
||
// RUN: %clang_cc1 -verify=ALL_NORMAL,NORMAL17,BOTH17,ALL_PRE20,ALLNORMAL,NORMAL_PRE20,ALL -std=c++17 %s | ||
// RUN: %clang_cc1 -verify=IMPLICIT17,IMPLICIT_PRE20,BOTH17,ALL_PRE20,ALLIMPLICIT,ALLIMPLICITOLD,ALL -fimplicit-constexpr -std=c++17 %s | ||
// RUN: %clang_cc1 -verify=IMPLICIT17,IMPLICIT_PRE20,BOTH17,ALL_PRE20,ALLIMPLICIT,ALLIMPLICITNEW,ALL -fimplicit-constexpr -std=c++17 %s -fexperimental-new-constant-interpreter | ||
|
||
// RUN: %clang_cc1 -verify=ALL_NORMAL,NORMAL20,BOTH20,ALLNORMAL,ALL -std=c++20 %s | ||
// RUN: %clang_cc1 -verify=IMPLICIT20,BOTH20,ALLIMPLICIT,ALLIMPLICITOLD,ALL -fimplicit-constexpr -std=c++20 %s | ||
// RUN: %clang_cc1 -verify=IMPLICIT20,BOTH20,ALLIMPLICIT,ALLIMPLICITNEW,ALL -fimplicit-constexpr -std=c++20 %s -fexperimental-new-constant-interpreter | ||
|
||
// RUN: %clang_cc1 -verify=ALL_NORMAL,NORMAL23,BOTH23,ALLNORMAL,ALL -std=c++23 %s | ||
// RUN: %clang_cc1 -verify=IMPLICIT23,BOTH23,ALLIMPLICIT,ALLIMPLICITOLD,ALL -fimplicit-constexpr -std=c++23 %s | ||
// RUN: %clang_cc1 -verify=IMPLICIT23,BOTH23,ALLIMPLICIT,ALLIMPLICITNEW,ALL -fimplicit-constexpr -std=c++23 %s -fexperimental-new-constant-interpreter | ||
|
||
|
||
|
||
|
||
// ============================================= | ||
// 1) simple uninlined function | ||
|
||
bool noinline_fnc() { | ||
// ALL-note@-1 {{declared here}} | ||
return true; | ||
} | ||
|
||
constexpr bool result_noinline_fnc = noinline_fnc(); | ||
// ALL-error@-1 {{constexpr variable 'result_noinline_fnc' must be initialized by a constant expression}} | ||
// ALLNORMAL-note@-2 {{non-constexpr function 'noinline_fnc' cannot be used in a constant expression}} | ||
// ALLIMPLICIT-note@-3 {{non-inline function 'noinline_fnc' is not implicitly constexpr}} | ||
|
||
|
||
// ============================================= | ||
// 2) simple inlined function | ||
|
||
inline bool inline_fnc() { | ||
// ALLNORMAL-note@-1 {{declared here}} | ||
return true; | ||
} | ||
|
||
constexpr bool result_inline_fnc = inline_fnc(); | ||
// ALLNORMAL-error@-1 {{constexpr variable 'result_inline_fnc' must be initialized by a constant expression}} | ||
// ALLNORMAL-note@-2 {{non-constexpr function 'inline_fnc' cannot be used in a constant expression}} | ||
|
||
|
||
// ============================================= | ||
// 3) undefined uninlined function | ||
|
||
bool noinline_undefined_fnc(); | ||
// ALL-note@-1 {{declared here}} | ||
|
||
constexpr bool result_noinline_undefined_fnc = noinline_undefined_fnc(); | ||
// ALL-error@-1 {{constexpr variable 'result_noinline_undefined_fnc' must be initialized by a constant expression}} | ||
// ALLNORMAL-note@-2 {{non-constexpr function 'noinline_undefined_fnc' cannot be used in a constant expression}} | ||
// ALLIMPLICITOLD-note@-3 {{undefined function 'noinline_undefined_fnc' cannot be used in a constant expression}} | ||
// ALLIMPLICITNEW-note@-4 {{non-inline function 'noinline_undefined_fnc' is not implicitly constexpr}} | ||
|
||
// ============================================= | ||
// 4) undefined inline function | ||
|
||
inline bool inline_undefined_fnc(); | ||
// ALL-note@-1 {{declared here}} | ||
|
||
constexpr bool result_inline_undefined_fnc = inline_undefined_fnc(); | ||
// ALL-error@-1 {{constexpr variable 'result_inline_undefined_fnc' must be initialized by a constant expression}} | ||
// ALLNORMAL-note@-2 {{non-constexpr function 'inline_undefined_fnc' cannot be used in a constant expression}} | ||
// ALLIMPLICIT-note@-3 {{undefined function 'inline_undefined_fnc' cannot be used in a constant expression}} | ||
|
||
// ============================================= | ||
// 5) lambda function | ||
|
||
auto lambda = [](int x) { return x > 0; }; | ||
// NORMAL14-note@-1 {{declared here}} | ||
|
||
constexpr bool result_lambda = lambda(10); | ||
// NORMAL14-error@-1 {{constexpr variable 'result_lambda' must be initialized by a constant expression}} | ||
// NORMAL14-note@-2 {{non-constexpr function 'operator()' cannot be used in a constant expression}} | ||
|
||
|
||
// ============================================= | ||
// 6) virtual functions | ||
|
||
struct type { | ||
virtual bool dispatch() const noexcept { | ||
return false; | ||
} | ||
}; | ||
|
||
struct child_of_type: type { | ||
bool dispatch() const noexcept override { | ||
// NORMAL20-note@-1 {{declared here}} | ||
// NORMAL23-note@-2 {{declared here}} | ||
return true; | ||
} | ||
}; | ||
|
||
constexpr bool result_virtual = static_cast<const type &>(child_of_type{}).dispatch(); | ||
// ALL_NORMAL-error@-1 {{constexpr variable 'result_virtual' must be initialized by a constant expression}} | ||
// NORMAL_PRE20-note@-2 {{cannot evaluate call to virtual function in a constant expression in C++ standards before C++20}} | ||
// IMPLICIT_PRE20-error@-3 {{constexpr variable 'result_virtual' must be initialized by a constant expression}} | ||
// IMPLICIT_PRE20-note@-4 {{cannot evaluate call to virtual function in a constant expression in C++ standards before C++20}} | ||
// NORMAL20-note@-5 {{non-constexpr function 'dispatch' cannot be used in a constant expression}} | ||
// NORMAL20-note@-6 {{declared here}} | ||
// NORMAL23-note@-7 {{non-constexpr function 'dispatch' cannot be used in a constant expression}} | ||
// NORMAL23-note@-8 {{declared here}} | ||
|
||
|
||
#if defined(__cpp_constexpr) && __cpp_constexpr >= 201907L | ||
static_assert(result_virtual == true, "virtual should work"); | ||
// ALL_NORMAL-error@-1 {{static assertion expression is not an integral constant expression}} | ||
// ALL_NORMAL-note@-2 {{initializer of 'result_virtual' is not a constant expression}} | ||
// IMPLICIT_PRE20-note@-3 {{initializer of 'result_virtual' is not a constant expression}} | ||
#endif | ||
|
||
|
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We don't usually define macros for non-standard feature. Instead users should use
__has_extension(cxx_implicit_constexpr)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is to mirror GCC's behavior, but I'm happy to remove it