[PATCH] D81616: [clang] Convert a default argument expression to the parameter type before checking that the default argument is valid with CheckDefaultArgumentVisitor.

Bruno Ricci via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Wed Jun 10 15:35:38 PDT 2020


riccibruno created this revision.
riccibruno added reviewers: bkramer, rjmccall, rsmith, erichkeane.
riccibruno added a project: clang.
Herald added a subscriber: cfe-commits.
riccibruno added a parent revision: D81615: [clang] CWG 2082 and 2346: loosen the restrictions on parameters and local variables in default arguments..

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.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D81616

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

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D81616.269978.patch
Type: text/x-patch
Size: 8336 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20200610/bef53ac3/attachment-0001.bin>


More information about the cfe-commits mailing list