[PATCH] D10881: [Sema] Catch a case when 'volatile' qualifier is dropped while binding
Davide Italiano
dccitaliano at gmail.com
Mon Jul 13 19:52:27 PDT 2015
davide removed rL LLVM as the repository for this revision.
davide updated this revision to Diff 29640.
davide added a comment.
Testcase.
http://reviews.llvm.org/D10881
Files:
lib/Sema/SemaInit.cpp
test/SemaCXX/bind-infinite-recursion.cpp
Index: test/SemaCXX/bind-infinite-recursion.cpp
===================================================================
--- test/SemaCXX/bind-infinite-recursion.cpp
+++ test/SemaCXX/bind-infinite-recursion.cpp
@@ -0,0 +1,18 @@
+// RUN: %clang_cc1 %s -fsyntax-only -verify
+
+struct S;
+
+struct W {
+ W( const S& ) {} // expected-note {{passing argument to parameter here}}
+};
+
+struct S {
+ S(volatile W) {}
+};
+
+int main() {
+ volatile W *w = 0;
+ S s(*w); // expected-error {{binding value of type 'volatile W' to reference to type 'const S' drops 'volatile' qualifier}}
+ return 0;
+}
+
Index: lib/Sema/SemaInit.cpp
===================================================================
--- lib/Sema/SemaInit.cpp
+++ lib/Sema/SemaInit.cpp
@@ -4087,6 +4087,12 @@
= S.CompareReferenceRelationship(DeclLoc, cv1T1, cv2T2, DerivedToBase,
ObjCConversion, ObjCLifetimeConversion);
+
+ if (isLValueRef && (!T1Quals.hasVolatile() && T2Quals.hasVolatile())) {
+ Sequence.SetFailed(InitializationSequence::FK_ReferenceInitDropsQualifiers);
+ return;
+ }
+
// C++0x [dcl.init.ref]p5:
// A reference to type "cv1 T1" is initialized by an expression of type
// "cv2 T2" as follows:
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D10881.29640.patch
Type: text/x-patch
Size: 1242 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20150714/1190a9a8/attachment.bin>
More information about the cfe-commits
mailing list