llvm-project/clang/test/CXX/dcl.decl
Bruno Ricci 40ea01f654
[clang] Convert a default argument expression to the parameter type...
...before checking that the default argument is valid with
CheckDefaultArgumentVisitor.

Currently the restrictions on a default argument are checked with the visitor
CheckDefaultArgumentVisitor in ActOnParamDefaultArgument before
performing the conversion to the parameter type in SetParamDefaultArgument.

This was fine before the previous patch but now some valid code post-CWG 2346
is rejected:

void test() {
  const int i2 = 0;
  extern void h2a(int x = i2);     // FIXME: ok, not odr-use
  extern void h2b(int x = i2 + 0); // ok, not odr-use
}

This is because the reference to i2 in h2a has not been marked yet with
NOUR_Constant. i2 is marked NOUR_Constant when the conversion to the parameter
type is done, which is done just after.

The solution is to do the conversion to the parameter type before checking
the restrictions on default arguments with CheckDefaultArgumentVisitor.
This has the side-benefit of improving some diagnostics.

Differential Revision: https://reviews.llvm.org/D81616

Reviewed By: rsmith
2020-06-11 13:18:45 +01:00
..
dcl.decomp PR40674: fix assertion failure if a structured binding declaration has a 2019-08-24 01:23:57 +00:00
dcl.fct.def Add -std=c++20 flag, replace C++2a with C++20 throughout the Clang 2020-02-18 16:16:37 -08:00
dcl.init PR23029 / C++ DR2233: Allow expanded parameter packs to follow 2020-06-02 13:48:59 -07:00
dcl.meaning [clang] Convert a default argument expression to the parameter type... 2020-06-11 13:18:45 +01:00
dcl.name
p4-0x.cpp Fix TryParsePtrOperatorSeq. 2020-02-24 08:08:47 -05:00