Files
clang-p2996/clang/test/CXX/expr/expr.post/expr.call/p4.cpp
Richard Smith b5f2c4e45b PR23029 / C++ DR2233: Allow expanded parameter packs to follow
parameters with default arguments.

Directly follow the wording by relaxing the AST invariant that all
parameters after one with a default arguemnt also have default
arguments, and removing the diagnostic on missing default arguments
on a pack-expanded parameter following a parameter with a default
argument.

Testing also revealed that we need to special-case explicit
specializations of templates with a pack following a parameter with a
default argument, as such explicit specializations are otherwise
impossible to write. The standard wording doesn't address this case; a
issue has been filed.

This exposed a bug where we would briefly consider a parameter to have
no default argument while we parse a delay-parsed default argument for
that parameter, which is also fixed.

Partially incorporates a patch by Raul Tambre.
2020-06-02 13:48:59 -07:00

23 lines
762 B
C++

// RUN: %clang_cc1 -verify %s
void a(int x = 0, int y); // #1 expected-error {{missing default argument on parameter 'y'}}
void b() {
a(); // expected-error {{no matching function}} expected-note@#1 {{requires 2 arguments, but 0 were provided}}
a(0); // expected-error {{no matching function}} expected-note@#1 {{requires 2 arguments, but 1 was provided}}
a(0, 0);
}
void a(int x, int y = 0);
void c() {
a();
a(0);
a(0, 0);
}
template<typename ...T> void f(int x = 0, T ...); // #2
void g() {
f<int>(); // expected-error {{no matching function}} expected-note@#2 {{requires 2 arguments, but 0 were provided}}
f<int>(0); // expected-error {{no matching function}} expected-note@#2 {{requires 2 arguments, but 1 was provided}}
f<int>(0, 0);
}