<div>On Thu Jan 30 2014 at 2:33:27 PM, Richard Smith <<a href="mailto:richard-llvm@metafoo.co.uk">richard-llvm@metafoo.co.uk</a>> wrote:</div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
Author: rsmith<br>
Date: Thu Jan 30 16:24:05 2014<br>
New Revision: 200496<br>
<br>
URL: <a href="http://llvm.org/viewvc/llvm-project?rev=200496&view=rev" target="_blank">http://llvm.org/viewvc/llvm-<u></u>project?rev=200496&view=rev</a><br>
Log:<br>
PR14995: Allow a dependent type as the second parameter of operator++ and<br>
operator--, since it might instantiate as 'int' (or, if it's a pack, it<br>
might instantiate as an empty pack).<br></blockquote><div><br></div><div>Oops, forgot to say: patch by Rahul Jain!</div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
Modified:<br>
cfe/trunk/lib/Sema/<u></u>SemaDeclCXX.cpp<br>
cfe/trunk/test/SemaCXX/<u></u>overloaded-operator.cpp<br>
<br>
Modified: cfe/trunk/lib/Sema/<u></u>SemaDeclCXX.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDeclCXX.cpp?rev=200496&r1=200495&r2=200496&view=diff" target="_blank">http://llvm.org/viewvc/llvm-<u></u>project/cfe/trunk/lib/Sema/<u></u>SemaDeclCXX.cpp?rev=200496&r1=<u></u>200495&r2=200496&view=diff</a><br>
==============================<u></u>==============================<u></u>==================<br>
--- cfe/trunk/lib/Sema/<u></u>SemaDeclCXX.cpp (original)<br>
+++ cfe/trunk/lib/Sema/<u></u>SemaDeclCXX.cpp Thu Jan 30 16:24:05 2014<br>
@@ -10909,11 +10909,10 @@ bool Sema::<u></u>CheckOverloadedOperatorDeclar<br>
// increment operator ++ for objects of that type.<br>
if ((Op == OO_PlusPlus || Op == OO_MinusMinus) && NumParams == 2) {<br>
ParmVarDecl *LastParam = FnDecl->getParamDecl(FnDecl-><u></u>getNumParams() - 1);<br>
- bool ParamIsInt = false;<br>
- if (const BuiltinType *BT = LastParam->getType()->getAs<<u></u>BuiltinType>())<br>
- ParamIsInt = BT->getKind() == BuiltinType::Int;<br>
+ QualType ParamType = LastParam->getType();<br>
<br>
- if (!ParamIsInt)<br>
+ if (!ParamType-><u></u>isSpecificBuiltinType(<u></u>BuiltinType::Int) &&<br>
+ !ParamType->isDependentType())<br>
return Diag(LastParam->getLocation(),<br>
diag::err_operator_overload_<u></u>post_incdec_must_be_int)<br>
<< LastParam->getType() << (Op == OO_MinusMinus);<br>
<br>
Modified: cfe/trunk/test/SemaCXX/<u></u>overloaded-operator.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/overloaded-operator.cpp?rev=200496&r1=200495&r2=200496&view=diff" target="_blank">http://llvm.org/viewvc/llvm-<u></u>project/cfe/trunk/test/<u></u>SemaCXX/overloaded-operator.<u></u>cpp?rev=200496&r1=200495&r2=<u></u>200496&view=diff</a><br>
==============================<u></u>==============================<u></u>==================<br>
--- cfe/trunk/test/SemaCXX/<u></u>overloaded-operator.cpp (original)<br>
+++ cfe/trunk/test/SemaCXX/<u></u>overloaded-operator.cpp Thu Jan 30 16:24:05 2014<br>
@@ -452,3 +452,58 @@ namespace PR7681 {<br>
Result = 1; // expected-error {{no viable overloaded '='}} // expected-note {{type 'PointerUnion<int *, float *>' is incomplete}}<br>
}<br>
}<br>
+<br>
+namespace PR14995 {<br>
+ struct B {};<br>
+ template<typename ...T> void operator++(B, T...) {}<br>
+<br>
+ void f() {<br>
+ B b;<br>
+ b++; // ok<br>
+ ++b; // ok<br>
+ }<br>
+<br>
+ template<typename... T><br>
+ struct C {<br>
+ void operator-- (T...) {}<br>
+ };<br>
+<br>
+ void g() {<br>
+ C<int> postfix;<br>
+ C<> prefix;<br>
+ postfix--; // ok<br>
+ --prefix; // ok<br>
+ }<br>
+<br>
+ struct D {};<br>
+ template<typename T> void operator++(D, T) {}<br>
+<br>
+ void h() {<br>
+ D d;<br>
+ d++; // ok<br>
+ ++d; // expected-error{{cannot increment value of type 'PR14995::D'}}<br>
+ }<br>
+<br>
+ template<typename...T> struct E {<br>
+ void operator++(T...) {} // expected-error{{parameter of overloaded post-increment operator must have type 'int' (not 'char')}}<br>
+ };<br>
+<br>
+ E<char> e; // expected-note {{in instantiation of template class 'PR14995::E<char>' requested here}}<br>
+<br>
+ struct F {<br>
+ template<typename... T><br>
+ int operator++ (T...) {}<br>
+ };<br>
+<br>
+ int k1 = F().operator++(0, 0);<br>
+ int k2 = F().operator++('0');<br>
+ // expected-error@-5 {{overloaded 'operator++' must be a unary or binary operator}}<br>
+ // expected-note@-3 {{in instantiation of function template specialization 'PR14995::F::operator++<int, int>' requested here}}<br>
+ // expected-error@-4 {{no matching member function for call to 'operator++'}}<br>
+ // expected-note@-8 {{candidate template ignored: substitution failure}}<br>
+ // expected-error@-9 {{parameter of overloaded post-increment operator must have type 'int' (not 'char')}}<br>
+ // expected-note@-6 {{in instantiation of function template specialization 'PR14995::F::operator++<char>' requested here}}<br>
+ // expected-error@-7 {{no matching member function for call to 'operator++'}}<br>
+ // expected-note@-12 {{candidate template ignored: substitution failure}}<br>
+} // namespace PR14995<br>
+<br>
<br>
<br>
______________________________<u></u>_________________<br>
cfe-commits mailing list<br>
<a href="mailto:cfe-commits@cs.uiuc.edu" target="_blank">cfe-commits@cs.uiuc.edu</a><br>
<a href="http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits" target="_blank">http://lists.cs.uiuc.edu/<u></u>mailman/listinfo/cfe-commits</a><br>
</blockquote>