[all-commits] [llvm/llvm-project] 40ea01: [clang] Convert a default argument expression to t...

Bruno Ricci via All-commits all-commits at lists.llvm.org
Thu Jun 11 05:19:32 PDT 2020


  Branch: refs/heads/master
  Home:   https://github.com/llvm/llvm-project
  Commit: 40ea01f6543d0d4aa2701d1b27a6c5413340e7d5
      https://github.com/llvm/llvm-project/commit/40ea01f6543d0d4aa2701d1b27a6c5413340e7d5
  Author: Bruno Ricci <riccibrun at gmail.com>
  Date:   2020-06-11 (Thu, 11 Jun 2020)

  Changed paths:
    M clang/include/clang/Sema/Sema.h
    M clang/lib/Sema/SemaDeclCXX.cpp
    M clang/lib/Sema/SemaTemplateInstantiate.cpp
    M clang/test/CXX/dcl.decl/dcl.meaning/dcl.fct.default/p7.cpp
    M clang/test/CXX/dcl.decl/dcl.meaning/dcl.fct.default/p8.cpp
    M clang/test/SemaCXX/vartemplate-lambda.cpp
    M clang/test/SemaTemplate/instantiate-local-class.cpp

  Log Message:
  -----------
  [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




More information about the All-commits mailing list