This is an archive of the discontinued LLVM Phabricator instance.

[clang] CWG 2082 and 2346: loosen the restrictions on parameters and local variables in default arguments.
ClosedPublic

Authored by riccibruno on Jun 10 2020, 3:02 PM.

Details

Summary

This patch implements the resolution of CWG 2082 and CWG 2346.

The resolution of CWG 2082 changed [dcl.fct.default]p7 and p9 to allow a parameter
or local variable to appear in a default argument if not in a potentially-evaluated expression.

The resolution of CWG 2346 changed [dcl.fct.default]p7 to allow a local variable
to appear in a default argument if not odr-used.

An issue remains after this patch (see the FIXME in test/CXX/dcl.decl/dcl.meaning/dcl.fct.default/p7.cpp).
This is addressed by the next patch.

Diff Detail

Event Timeline

riccibruno created this revision.Jun 10 2020, 3:02 PM
rsmith accepted this revision.Jun 10 2020, 4:15 PM
rsmith marked 2 inline comments as done.
rsmith added inline comments.
clang/lib/Sema/SemaDeclCXX.cpp
98

I think this is an oversight, and we should probably allow all non-odr-use mentions here. I'll take this to the committee to check. But let's go with the rule as written for now.

114

Do we perform this check after finishing the full-expression and properly setting the 'non-odr-use' bits? Oh, I see, that's what the follow-up change is about :)

This revision is now accepted and ready to land.Jun 10 2020, 4:15 PM
erichkeane accepted this revision.Jun 10 2020, 4:15 PM

This looks like the right interpretation of the standard/implementation to me. But please do not commit on this accept for another day or two to give the rest a chance to look.

rsmith added inline comments.Jun 10 2020, 5:47 PM
clang/test/CXX/dcl.decl/dcl.meaning/dcl.fct.default/p9.cpp
9

I'd like to see an example like:

void f5(int x, int y = ((void)x, 0));

to demonstrate that we're checking for potentially-evaluated mentions, not odr-uses, here. ((void)x is not an odr-use, but is potentially-evaluated.)

riccibruno marked an inline comment as done.

Add the example in clang/test/CXX/dcl.decl/dcl.meaning/dcl.fct.default/p9.cpp as requested.

This revision was automatically updated to reflect the committed changes.