r213609 - Fix a template diffing problem were an '&' is unexpectedly printed in
Benjamin Kramer
benny.kra at gmail.com
Tue Jul 22 06:47:27 PDT 2014
On Tue, Jul 22, 2014 at 5:33 AM, Richard Trieu <rtrieu at google.com> wrote:
> Author: rtrieu
> Date: Mon Jul 21 22:33:01 2014
> New Revision: 213609
>
> URL: http://llvm.org/viewvc/llvm-project?rev=213609&view=rev
> Log:
> Fix a template diffing problem were an '&' is unexpectedly printed in
> a template argument.
>
> Modified:
> cfe/trunk/lib/AST/ASTDiagnostic.cpp
> cfe/trunk/test/Misc/diag-template-diffing.cpp
>
> Modified: cfe/trunk/lib/AST/ASTDiagnostic.cpp
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/ASTDiagnostic.cpp?rev=213609&r1=213608&r2=213609&view=diff
> ==============================================================================
> --- cfe/trunk/lib/AST/ASTDiagnostic.cpp (original)
> +++ cfe/trunk/lib/AST/ASTDiagnostic.cpp Mon Jul 21 22:33:01 2014
> @@ -991,12 +991,32 @@ class TemplateDiff {
> if (!HasToValueDecl && ToExpr)
> ToValueDecl = GetValueDecl(ToIter, ToExpr);
> QualType ArgumentType = DefaultNTTPD->getType();
> - bool FromAddressOf = FromValueDecl &&
> - !ArgumentType->isReferenceType() &&
> - !FromValueDecl->getType()->isArrayType();
> - bool ToAddressOf = ToValueDecl &&
> - !ArgumentType->isReferenceType() &&
> - !ToValueDecl->getType()->isArrayType();
> + bool FromAddressOf = false;
> + if (FromValueDecl) {
> + if (FromExpr) {
> + if (UnaryOperator *UO = dyn_cast<UnaryOperator>(FromExpr)) {
> + if (UO->getOpcode() == UO_AddrOf)
> + FromAddressOf = true;
> + }
> + } else {
> + if (!ArgumentType->isReferenceType()) {
> + FromAddressOf = true;
> + }
> + }
> + }
> + bool ToAddressOf = false;
> + if (ToValueDecl) {
> + if (ToExpr) {
> + if (UnaryOperator *UO = dyn_cast<UnaryOperator>(ToExpr)) {
> + if (UO->getOpcode() == UO_AddrOf) {
> + ToAddressOf = true;
> + }
> + }
> + } else {
> + if (!ArgumentType->isReferenceType())
> + ToAddressOf = true;
> + }
> + }
Ugh, can you factor this into a predicate function? The code
duplication is nasty. Early exits could also help to reduce the depth
of nested ifs a bit in a helper function.
- Ben
> Tree.SetNode(FromValueDecl, ToValueDecl, FromAddressOf, ToAddressOf);
> Tree.SetSame(FromValueDecl && ToValueDecl &&
> FromValueDecl->getCanonicalDecl() ==
>
> Modified: cfe/trunk/test/Misc/diag-template-diffing.cpp
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Misc/diag-template-diffing.cpp?rev=213609&r1=213608&r2=213609&view=diff
> ==============================================================================
> --- cfe/trunk/test/Misc/diag-template-diffing.cpp (original)
> +++ cfe/trunk/test/Misc/diag-template-diffing.cpp Mon Jul 21 22:33:01 2014
> @@ -1105,6 +1105,22 @@ using F = C<21 + 21>;
> }
> }
>
> +namespace AddressOf {
> +template <int*>
> +struct S {};
> +
> +template <class T>
> +struct Wrapper {};
> +
> +template <class T>
> +Wrapper<T> MakeWrapper();
> +int global;
> +constexpr int * ptr = nullptr;
> +Wrapper<S<ptr>> W = MakeWrapper<S<&global>>();
> +// Don't print an extra '&' for 'ptr'
> +// CHECK-ELIDE-NOTREE: no viable conversion from 'Wrapper<S<&global>>' to 'Wrapper<S<ptr>>'
> +}
> +
> // CHECK-ELIDE-NOTREE: {{[0-9]*}} errors generated.
> // CHECK-NOELIDE-NOTREE: {{[0-9]*}} errors generated.
> // CHECK-ELIDE-TREE: {{[0-9]*}} errors generated.
>
>
> _______________________________________________
> cfe-commits mailing list
> cfe-commits at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits
More information about the cfe-commits
mailing list