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