-
Notifications
You must be signed in to change notification settings - Fork 11.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Clang][Sema] Prohibit statement expression in the default argument
As statement expression makes no sense in the default argument, this patch tries to disable it in the all cases. Please note that the statement expression is a GNU extension, which means that Clang should be consistent with GCC. However, there's no response from GCC devs since we have raised the issue for several weeks. In this case, I think we can disallow statement expressions as a default parameter in general for now, and relax the restriction if GCC folks decide to retain the feature for functions but not lambdas in the future. Related discussion: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=104765 Fixes #53488 Differential Revision: https://reviews.llvm.org/D119609
- Loading branch information
Showing
6 changed files
with
61 additions
and
21 deletions.
There are no files selected for viewing
This file contains 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 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 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 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 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,29 @@ | ||
// RUN: %clang_cc1 %s -fsyntax-only -verify -std=c++20 | ||
|
||
void foo() { | ||
void fn(int i, int = ({ 1; })); // expected-error {{default argument may not use a GNU statement expression}} | ||
|
||
auto a = [](int = ({ 1; })) {}; // expected-error {{default argument may not use a GNU statement expression}} | ||
|
||
auto b = []<int = ({ 1; })>(){}; // expected-error {{default non-type template argument may not use a GNU statement expression}} | ||
|
||
void fn(int i, int j = ({{}, {}, {,}}), int k = ""); // expected-error {{default argument may not use a GNU statement expression}} expected-error {{cannot initialize a parameter of type 'int' with an lvalue of type 'const char[1]'}} expected-note {{passing argument to parameter 'k' here}} | ||
} | ||
|
||
template <int foo = ({ 1; })> // expected-error {{default non-type template argument may not use a GNU statement expression}} | ||
void f() {} | ||
|
||
template <int bar = ({ 1; })> // expected-error {{default non-type template argument may not use a GNU statement expression}} | ||
class S {}; | ||
|
||
template <typename Callable> | ||
int bar(Callable &&Call) { | ||
return Call(); | ||
} | ||
|
||
int baz() { | ||
auto l = [](int a = ({ int x = 12; x; })) { // expected-error {{default argument may not use a GNU statement expression}} | ||
return 1; | ||
}; | ||
return bar(l); | ||
} |
This file contains 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