[test] Make tests pass regardless of gnu++14/gnu++17 default
GCC from 11 onwards defaults to -std=gnu++17 for C++ source files. We want to do the same
(https://discourse.llvm.org/t/c-objc-switch-to-gnu-17-as-the-default-dialect/64360).
Split RUN lines, adjust `-verify`, or add `__cplusplus < 201703L` or `-Wno-dynamic-exception-spec`,
so that tests will pass regardless of gnu++14/gnu++17 default.
We have a desire to mark a test compatible with multiple language standards.
There are ongoing discussions how to add markers in the long term:
* https://discourse.llvm.org/t/iterating-lit-run-lines/62596
* https://discourse.llvm.org/t/lit-run-a-run-line-multiple-times-with-different-replacements/64932
As a workaround in the short term, add lit substitutions `%std_cxx98-`,
`%std_cxx11-14`, etc. They can be used for tests which work across multiple
language standards. If a range has `n` standards, run lit multiple times, with
`LIT_CLANG_STD_GROUP=0`, `LIT_CLANG_STD_GROUP=1`, etc to cover all `n` standards.
Reviewed By: #clang-language-wg, aaron.ballman
Differential Revision: https://reviews.llvm.org/D131464
2022-09-04 05:29:32 +00:00
|
|
|
// RUN: %clang_cc1 -fsyntax-only -verify=expected,precxx17 %std_cxx11-14 %s
|
|
|
|
// RUN: %clang_cc1 -fsyntax-only -verify=expected,cxx17 %std_cxx17- %s
|
2009-02-08 10:28:44 +00:00
|
|
|
|
2008-04-08 04:40:51 +00:00
|
|
|
void f(int i, int j, int k = 3);
|
2008-05-07 04:49:29 +00:00
|
|
|
void f(int i, int j, int k);
|
2008-04-08 04:40:51 +00:00
|
|
|
void f(int i, int j = 2, int k);
|
2008-05-07 04:49:29 +00:00
|
|
|
void f(int i, int j, int k);
|
2008-04-08 04:40:51 +00:00
|
|
|
void f(int i = 1, int j, int k);
|
2008-05-07 04:49:29 +00:00
|
|
|
void f(int i, int j, int k);
|
2008-04-08 04:40:51 +00:00
|
|
|
|
|
|
|
void i()
|
|
|
|
{
|
|
|
|
f();
|
|
|
|
f(0);
|
|
|
|
f(0, 1);
|
|
|
|
f(0, 1, 2);
|
|
|
|
}
|
2008-04-10 02:22:51 +00:00
|
|
|
|
|
|
|
|
2010-02-22 00:40:25 +00:00
|
|
|
int f1(int i, // expected-note {{previous declaration is here}}
|
|
|
|
int i, int j) { // expected-error {{redefinition of parameter 'i'}}
|
2008-04-10 02:22:51 +00:00
|
|
|
i = 17;
|
|
|
|
return j;
|
|
|
|
}
|
|
|
|
|
|
|
|
int x;
|
|
|
|
void g(int x, int y = x); // expected-error {{default argument references parameter 'x'}}
|
|
|
|
|
2008-04-12 23:52:44 +00:00
|
|
|
void g2(int x, int y, int z = x + y); // expected-error {{default argument references parameter 'x'}} expected-error {{default argument references parameter 'y'}}
|
2008-05-07 04:49:29 +00:00
|
|
|
|
2008-11-03 22:47:57 +00:00
|
|
|
class X {
|
2012-04-05 01:13:04 +00:00
|
|
|
void f(X* x = this); // expected-error{{invalid use of 'this' outside of a non-static member function}}
|
2008-11-04 13:41:56 +00:00
|
|
|
|
|
|
|
void g() {
|
|
|
|
int f(X* x = this); // expected-error{{default argument references 'this'}}
|
|
|
|
}
|
2008-11-03 22:47:57 +00:00
|
|
|
};
|
2008-12-16 00:08:34 +00:00
|
|
|
|
|
|
|
// C++ [dcl.fct.default]p6
|
|
|
|
class C {
|
|
|
|
static int x;
|
|
|
|
void f(int i = 3); // expected-note{{previous definition is here}}
|
|
|
|
void g(int i, int j = x);
|
|
|
|
|
|
|
|
void h();
|
|
|
|
};
|
|
|
|
void C::f(int i = 3) // expected-error{{redefinition of default argument}}
|
|
|
|
{ }
|
|
|
|
|
|
|
|
void C::g(int i = 88, int j) {}
|
|
|
|
|
|
|
|
void C::h() {
|
|
|
|
g(); // okay
|
|
|
|
}
|
|
|
|
|
|
|
|
// C++ [dcl.fct.default]p9
|
2008-12-16 21:30:33 +00:00
|
|
|
struct Y {
|
2008-12-16 00:08:34 +00:00
|
|
|
int a;
|
2012-04-05 01:13:04 +00:00
|
|
|
int mem1(int i = a); // expected-error{{invalid use of non-static data member 'a'}}
|
2008-12-16 21:30:33 +00:00
|
|
|
int mem2(int i = b); // OK; use Y::b
|
2008-12-16 00:38:16 +00:00
|
|
|
int mem3(int i);
|
|
|
|
int mem4(int i);
|
2008-12-16 21:30:33 +00:00
|
|
|
|
|
|
|
struct Nested {
|
|
|
|
int mem5(int i = b, // OK; use Y::b
|
|
|
|
int j = c, // OK; use Y::Nested::c
|
|
|
|
int k = j, // expected-error{{default argument references parameter 'j'}}
|
2012-04-05 01:13:04 +00:00
|
|
|
int l = a, // expected-error{{invalid use of non-static data member 'a'}}
|
|
|
|
Nested* self = this, // expected-error{{invalid use of 'this' outside of a non-static member function}}
|
2008-12-16 21:30:33 +00:00
|
|
|
int m); // expected-error{{missing default argument on parameter 'm'}}
|
|
|
|
static int c;
|
2010-10-12 16:25:54 +00:00
|
|
|
Nested(int i = 42);
|
2008-12-16 21:30:33 +00:00
|
|
|
};
|
|
|
|
|
2010-10-12 16:25:54 +00:00
|
|
|
int mem7(Nested n = Nested());
|
|
|
|
|
2008-12-16 00:08:34 +00:00
|
|
|
static int b;
|
|
|
|
};
|
2008-12-16 00:38:16 +00:00
|
|
|
|
|
|
|
int Y::mem3(int i = b) { return i; } // OK; use X::b
|
|
|
|
|
2012-04-05 01:13:04 +00:00
|
|
|
int Y::mem4(int i = a) // expected-error{{invalid use of non-static data member 'a'}}
|
2008-12-16 00:38:16 +00:00
|
|
|
{ return i; }
|
2008-12-16 21:30:33 +00:00
|
|
|
|
|
|
|
|
|
|
|
// Try to verify that default arguments interact properly with copy
|
|
|
|
// constructors.
|
|
|
|
class Z {
|
|
|
|
public:
|
2010-01-06 09:43:14 +00:00
|
|
|
Z(Z&, int i = 17); // expected-note 3 {{candidate constructor}}
|
2008-12-16 21:30:33 +00:00
|
|
|
|
|
|
|
void f(Z& z) {
|
|
|
|
Z z2; // expected-error{{no matching constructor for initialization}}
|
|
|
|
Z z3(z);
|
|
|
|
}
|
2008-12-24 00:01:03 +00:00
|
|
|
|
|
|
|
void test_Z(const Z& z) {
|
2010-03-10 11:27:22 +00:00
|
|
|
Z z2(z); // expected-error{{no matching constructor for initialization of 'Z'}}
|
2008-12-24 00:01:03 +00:00
|
|
|
}
|
2008-12-16 21:30:33 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
void test_Z(const Z& z) {
|
2010-03-10 11:27:22 +00:00
|
|
|
Z z2(z); // expected-error{{no matching constructor for initialization of 'Z'}}
|
2008-12-16 21:30:33 +00:00
|
|
|
}
|
2008-12-24 00:01:03 +00:00
|
|
|
|
|
|
|
struct ZZ {
|
|
|
|
static ZZ g(int = 17);
|
|
|
|
|
[test] Make tests pass regardless of gnu++14/gnu++17 default
GCC from 11 onwards defaults to -std=gnu++17 for C++ source files. We want to do the same
(https://discourse.llvm.org/t/c-objc-switch-to-gnu-17-as-the-default-dialect/64360).
Split RUN lines, adjust `-verify`, or add `__cplusplus < 201703L` or `-Wno-dynamic-exception-spec`,
so that tests will pass regardless of gnu++14/gnu++17 default.
We have a desire to mark a test compatible with multiple language standards.
There are ongoing discussions how to add markers in the long term:
* https://discourse.llvm.org/t/iterating-lit-run-lines/62596
* https://discourse.llvm.org/t/lit-run-a-run-line-multiple-times-with-different-replacements/64932
As a workaround in the short term, add lit substitutions `%std_cxx98-`,
`%std_cxx11-14`, etc. They can be used for tests which work across multiple
language standards. If a range has `n` standards, run lit multiple times, with
`LIT_CLANG_STD_GROUP=0`, `LIT_CLANG_STD_GROUP=1`, etc to cover all `n` standards.
Reviewed By: #clang-language-wg, aaron.ballman
Differential Revision: https://reviews.llvm.org/D131464
2022-09-04 05:29:32 +00:00
|
|
|
void f(ZZ z = g()); // precxx17-error{{no matching constructor for initialization}} \
|
|
|
|
// precxx17-note{{passing argument to parameter 'z' here}}
|
2009-06-12 16:51:40 +00:00
|
|
|
|
[test] Make tests pass regardless of gnu++14/gnu++17 default
GCC from 11 onwards defaults to -std=gnu++17 for C++ source files. We want to do the same
(https://discourse.llvm.org/t/c-objc-switch-to-gnu-17-as-the-default-dialect/64360).
Split RUN lines, adjust `-verify`, or add `__cplusplus < 201703L` or `-Wno-dynamic-exception-spec`,
so that tests will pass regardless of gnu++14/gnu++17 default.
We have a desire to mark a test compatible with multiple language standards.
There are ongoing discussions how to add markers in the long term:
* https://discourse.llvm.org/t/iterating-lit-run-lines/62596
* https://discourse.llvm.org/t/lit-run-a-run-line-multiple-times-with-different-replacements/64932
As a workaround in the short term, add lit substitutions `%std_cxx98-`,
`%std_cxx11-14`, etc. They can be used for tests which work across multiple
language standards. If a range has `n` standards, run lit multiple times, with
`LIT_CLANG_STD_GROUP=0`, `LIT_CLANG_STD_GROUP=1`, etc to cover all `n` standards.
Reviewed By: #clang-language-wg, aaron.ballman
Differential Revision: https://reviews.llvm.org/D131464
2022-09-04 05:29:32 +00:00
|
|
|
ZZ(ZZ&, int = 17); // precxx17-note{{candidate constructor}}
|
2008-12-24 00:01:03 +00:00
|
|
|
};
|
2009-06-12 16:51:40 +00:00
|
|
|
|
|
|
|
// http://www.open-std.org/jtc1/sc22/wg21/docs/cwg_active.html#325
|
|
|
|
class C2 {
|
|
|
|
static void g(int = f()); // expected-error{{use of default argument to function 'f' that is declared later in class 'C2'}}
|
|
|
|
static int f(int = 10); // expected-note{{default argument declared here}}
|
|
|
|
};
|
2009-07-22 21:45:50 +00:00
|
|
|
|
2020-07-18 20:39:16 +01:00
|
|
|
template <typename T> class C3;
|
|
|
|
template <> class C3<int> {
|
[clang] Pass the NamedDecl* instead of the DeclarationName into many diagnostics.
Background:
-----------
There are two related argument types which can be sent into a diagnostic to
display the name of an entity: DeclarationName (ak_declarationname) or
NamedDecl* (ak_nameddecl) (there is also ak_identifierinfo for
IdentifierInfo*, but we are not concerned with it here).
A DeclarationName in a diagnostic will just be streamed to the output,
which will directly result in a call to DeclarationName::print.
A NamedDecl* in a diagnostic will also ultimately result in a call to
DeclarationName::print, but with two customisation points along the way:
The first customisation point is NamedDecl::getNameForDiagnostic which is
overloaded by FunctionDecl, ClassTemplateSpecializationDecl and
VarTemplateSpecializationDecl to print the template arguments, if any.
The second customisation point is NamedDecl::printName. By default it just
streams the stored DeclarationName into the output but it can be customised
to provide a user-friendly name for an entity. It is currently overloaded by
DecompositionDecl and MSGuidDecl.
What this patch does:
---------------------
For many diagnostics a DeclarationName is used instead of the NamedDecl*.
This bypasses the two customisation points mentioned above. This patches fix
this for diagnostics in Sema.cpp, SemaCast.cpp, SemaChecking.cpp, SemaDecl.cpp,
SemaDeclAttr.cpp, SemaDecl.cpp, SemaOverload.cpp and SemaStmt.cpp.
I have only modified diagnostics where I could construct a test-case which
demonstrates that the change is appropriate (either with this patch or the next
one).
Reviewed By: erichkeane, aaron.ballman
Differential Revision: https://reviews.llvm.org/D84656
2020-07-27 23:22:21 +01:00
|
|
|
static void g(int = f()); // expected-error {{use of default argument to function 'f' that is declared later in class 'C3<int>'}}
|
2020-07-18 20:39:16 +01:00
|
|
|
static int f(int = 10); // expected-note {{default argument declared here}}
|
|
|
|
};
|
|
|
|
|
2009-07-22 21:45:50 +00:00
|
|
|
// Make sure we actually parse the default argument for an inline definition
|
|
|
|
class XX {
|
|
|
|
void A(int length = -1 ) { }
|
|
|
|
void B() { A(); }
|
|
|
|
};
|
2014-12-02 23:32:20 +00:00
|
|
|
|
|
|
|
template <int I = (1 * I)> struct S {}; // expected-error-re {{use of undeclared identifier 'I'{{$}}}}
|
|
|
|
S<1> s;
|
|
|
|
|
|
|
|
template <int I1 = I2, int I2 = 1> struct T {}; // expected-error-re {{use of undeclared identifier 'I2'{{$}}}}
|
|
|
|
T<0, 1> t;
|
2016-06-14 02:55:56 +00:00
|
|
|
|
|
|
|
struct PR28105 {
|
2020-04-06 19:17:55 -07:00
|
|
|
PR28105 (int = 0, int = 0,
|
|
|
|
PR28105 // expected-error{{recursive evaluation of default argument}}
|
|
|
|
=
|
|
|
|
0); // expected-note {{default argument used here}}
|
2016-06-14 02:55:56 +00:00
|
|
|
};
|