[cfe-dev] f6a164819 We don't want to throw lvalue-to-rvalue casts (...) of certain types in C++ (was: Allow implicit copy constructor (...))

Richard Smith richard at metafoo.co.uk
Sun May 4 12:26:27 PDT 2014


On Sun, May 4, 2014 at 4:53 AM, Adam Strzelecki <ono at java.pl> wrote:

> John, I kindly ask for an explanation of following change introduced by
> you in f6a164819:
>
> git diff f6a164819^! lib/Sema/SemaExpr.cpp
>
> +    // We don't want to throw lvalue-to-rvalue casts on top of
> +    // expressions of certain types in C++.
> +    if (getLangOptions().CPlusPlus &&
> +        (E->getType() == Context.OverloadTy ||
> +         T->isDependentType() ||
> +         T->isRecordType()))
> +      return;
>
> The problem with this change is that I explicitly request to use C style
> assignment (ignoring constructors) on POD type variable having `pod_assign`
> attribute, but condition above prevents proper cast to be emitted.
>

You're trying to shoehorn non-C++ semantics into C++, so you're going to
have a bad time. The above check is appropriate for C++ (CK_LValueToRValue
is not something that should ever happen to a record type in C++, because
that's not what the lvalue-to-rvalue conversion does on record types).


> So far I have simply disabled, since I no longer have direct access to the
> Entity (VarDecl) to check for PODAssignAttrt, but I am not sure what are
> consequences of such step.
>
> FYI:
>
>
> https://github.com/ujhpc/clang/commit/61823c2bc5be78f793bdc8c11365d2bcb50455cc
>
> +++ b/lib/Sema/SemaInit.cpp
> @@ -4599,6 +4599,10 @@ void InitializationSequence::InitializeFrom(Sema &S,
>
>    //     - If the destination type is a (possibly cv-qualified) class
> type:
>    if (DestType->isRecordType()) {
> +    if (Entity.getDecl()->hasAttr<PODAssignAttr>()) {
> +      AddCAssignmentStep(DestType);
> +      return;
> +    }
>
> Regards,
> --
> Adam
> _______________________________________________
> cfe-dev mailing list
> cfe-dev at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20140504/a91d8e48/attachment.html>


More information about the cfe-dev mailing list