[PATCH] D39679: [C++11] Fix warning when dropping cv-qualifiers when assigning to a reference with a braced initializer list
Nicolas Lesser via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Thu Jan 4 15:25:36 PST 2018
Rakete1111 updated this revision to Diff 128661.
Rakete1111 added a comment.
Rebased + friendly 2018 ping :)
https://reviews.llvm.org/D39679
Files:
lib/Sema/SemaInit.cpp
test/SemaCXX/references.cpp
Index: test/SemaCXX/references.cpp
===================================================================
--- test/SemaCXX/references.cpp
+++ test/SemaCXX/references.cpp
@@ -1,4 +1,5 @@
// RUN: %clang_cc1 -fsyntax-only -verify %s
+// RUN: %clang_cc1 -std=c++11 -fsyntax-only -verify %s
int g(int);
void f() {
@@ -55,6 +56,13 @@
// const double& rcd2 = 2; // rcd2 refers to temporary with value 2.0
const volatile int cvi = 1;
const int& r = cvi; // expected-error{{binding value of type 'const volatile int' to reference to type 'const int' drops 'volatile' qualifier}}
+
+#if __cplusplus >= 201103L
+ const int& r2{cvi}; // expected-error{{binding value of type 'const volatile int' to reference to type 'const int' drops 'volatile' qualifier}}
+
+ const int a = 2;
+ int& r3{a}; // expected-error{{binding value of type 'const int' to reference to type 'int' drops 'const'}}
+#endif
}
// C++ [dcl.init.ref]p3
Index: lib/Sema/SemaInit.cpp
===================================================================
--- lib/Sema/SemaInit.cpp
+++ lib/Sema/SemaInit.cpp
@@ -7696,6 +7696,12 @@
case FK_ReferenceInitDropsQualifiers: {
QualType SourceType = Args[0]->getType();
+
+ // For braced initializer lists, we want to get the type
+ // of its (only) element, and not the "type" of the list itself.
+ if (const auto *List = dyn_cast<InitListExpr>(Args[0]))
+ SourceType = List->getInit(0)->getType();
+
QualType NonRefType = DestType.getNonReferenceType();
Qualifiers DroppedQualifiers =
SourceType.getQualifiers() - NonRefType.getQualifiers();
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D39679.128661.patch
Type: text/x-patch
Size: 1602 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20180104/5c5b3100/attachment-0001.bin>
More information about the cfe-commits
mailing list