This is an archive of the discontinued LLVM Phabricator instance.

[C++11] Fix warning when dropping cv-qualifiers when assigning to a reference with a braced initializer list
ClosedPublic

Authored by Rakete1111 on Nov 6 2017, 3:35 AM.

Details

Reviewers
rsmith
Summary

This fixes PR34912 :)

Diff Detail

Event Timeline

Rakete1111 updated this revision to Diff 121712.Nov 6 2017, 3:35 AM
Rakete1111 created this revision.
Rakete1111 updated this revision to Diff 128661.Jan 4 2018, 3:25 PM

Rebased + friendly 2018 ping :)

rsmith added inline comments.Jan 4 2018, 3:42 PM
lib/Sema/SemaInit.cpp
7691–7695

Same problem exists here, and probably in a lot of these diagnostics. For example:

*int a; int &&b = {a}; says "cannot bind to lvalue of type 'void'")

  • void f(int); void f() { int &&b = {f}; } asserts due to not unwrapping the InitListExpr before trying to diagnose

Can you try to address this more generally? Perhaps: add an Expr *OnlyArg, which is null if Args.size() != 1, is the list element if Args.size() == 1 and is an InitListExpr with a single element, and is otherwise Args[0], and change all the diagnostics that are talking about a one-and-only argument to use OnlyArg?

Addressed review comments :)
I added a test case for the crashing code.

Note: I didn't change Args[0] to OnlyArg in FK_AddressOfUnaddressableFunction, because I'm pretty sure that C++ doesn't have unaddressable functions and thus there is no need to decompose an initializer list. Is this correct?

Rakete1111 marked an inline comment as done.Mar 14 2018, 11:34 AM

Rebased + friendly ping :)

Rebased + friendly ping :)

Note: I didn't change Args[0] to OnlyArg in FK_AddressOfUnaddressableFunction, because I'm pretty sure that C++ doesn't have unaddressable functions and thus there is no need to decompose an initializer list. Is this correct?

C++ with Clang extensions has unaddressable functions. This example asserts at the moment:

void f() __attribute__((enable_if(false, "")));
int f();
void (&&p)() = {f};

... due, I think, to failing to unwrap the initializer list when diagnosing the initialization.

rsmith accepted this revision.Jun 21 2018, 1:47 PM

In any case, this looks good to me. It'll look even better with the FK_AddressOfUnaddressableFunction case fixed :)

This revision is now accepted and ready to land.Jun 21 2018, 1:47 PM

done :)
Could you commit it please, @rsmith ?

Rebased + friendly ping :)

Rakete1111 closed this revision.Jul 12 2018, 10:49 AM

Committed in r336922 :)