Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[clang] CWG 2082 and 2346: loosen the restrictions on parameters and …
…local variables in default arguments. This patch implements the resolution of CWG 2082 and CWG 2346. The resolution of CWG 2082 changed [dcl.fct.default]p7 and p9 to allow a parameter or local variable to appear in a default argument if not in a potentially-evaluated expression. The resolution of CWG 2346 changed [dcl.fct.default]p7 to allow a local variable to appear in a default argument if not odr-used. An issue remains after this patch (see the FIXME in test/CXX/dcl.decl/dcl.meaning/dcl.fct.default/p7.cpp). This is addressed by the next patch. Differential Revision: https://reviews.llvm.org/D81615 Reviewed By: rsmith, erichkeane
- Loading branch information
1 parent
0418005
commit 5951ff4
Showing
6 changed files
with
71 additions
and
17 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
21 changes: 17 additions & 4 deletions
21
clang/test/CXX/dcl.decl/dcl.meaning/dcl.fct.default/p7.cpp
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 |
---|---|---|
@@ -1,7 +1,20 @@ | ||
// RUN: %clang_cc1 -fsyntax-only -verify %s | ||
|
||
void h() | ||
{ | ||
int i; | ||
extern void h2(int x = sizeof(i)); // expected-error {{default argument references local variable 'i' of enclosing function}} | ||
void h() { | ||
int i1 = 0; | ||
extern void h1(int x = i1); | ||
// expected-error@-1 {{default argument references local variable 'i1' of enclosing function}} | ||
|
||
const int i2 = 0; | ||
extern void h2a(int x = i2); // FIXME: ok, not odr-use | ||
// expected-error@-1 {{default argument references local variable 'i2' of enclosing function}} | ||
extern void h2b(int x = i2 + 0); // ok, not odr-use | ||
|
||
const int i3 = 0; | ||
extern void h3(const int *x = &i3); | ||
// expected-error@-1 {{default argument references local variable 'i3' of enclosing function}} | ||
|
||
const int i4 = 0; | ||
extern void h4(int x = sizeof(i4)); // ok, not odr-use | ||
extern void h5(int x = decltype(i4 + 4)()); // ok, not odr-use | ||
} |
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 |
---|---|---|
@@ -1,4 +1,10 @@ | ||
// RUN: %clang_cc1 -fsyntax-only -verify %s | ||
class A { | ||
void f(A* p = this) { } // expected-error{{invalid use of 'this'}} | ||
|
||
void test(); | ||
}; | ||
|
||
void A::test() { | ||
void g(int = this); // expected-error {{default argument references 'this'}} | ||
} |
12 changes: 12 additions & 0 deletions
12
clang/test/CXX/dcl.decl/dcl.meaning/dcl.fct.default/p9.cpp
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,12 @@ | ||
// RUN: %clang_cc1 -fsyntax-only -verify %s | ||
|
||
void h() { | ||
void f1(int x, int y = sizeof(x)); // ok | ||
void f2(int x, int y = decltype(x)()); // ok | ||
void f3(int x, int y = x); | ||
// expected-error@-1 {{default argument references parameter 'x'}} | ||
void f4(int x, int y = x + 0); | ||
// expected-error@-1 {{default argument references parameter 'x'}} | ||
void f5(int x, int y = ((void)x, 0)); | ||
// expected-error@-1 {{default argument references parameter 'x'}} | ||
} |
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