Re: OpenCOLLADA need a little c++ help

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Richard Shaw writes:

error: possibly dangling reference to a temporary [-Werror=dangling- reference]   315 |                 const auto & parents = dae.root().selectNodes("//*[@sid]/..");

This is a complaint about a potential problem that might, just might be true. It can't be determined without inspecting the contents of the function. The diagnostic does not, and just assumes the worst.

TLDR: if a function call parameter is a const ref, and gets initialized from a prvalue, and the function returns the same const ref type, gcc will whine about a potential dangling reference being used, on the theory that the function might be returning the same const ref that's getting passed into it, but the temporary prvalue gets destroyed at the end of the statement.

That's literally what this error means.

The discussion in gcc's bug tracker discovered that gcc will emit this warning solely based on the function's signature and without considering the contents of the function. It just assumes that this might be a problem here and helpfully raises its hand.

The quickest solution is just add a pragma to shut it up.

The code in question[2] is:
  // InstanceWithExtra and other <instance_*> with "url" attribute
const auto & instances = root().selectNodes(

Find where selectNodes() is defined. Add

#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wdangling-reference"

before the definition, and

#pragma GCC diagnostic pop

after it.

This all presumes that this is a false positive, which I'll estimate will be the case more often than not.


There's a 2nd instance of the error but I think I can fix it once the path forward on the first is addressed.

What are the odds that the 2nd occurence of this is an actual problem?

Attachment: pgpYBCiRcmVRO.pgp
Description: PGP signature

_______________________________________________
devel mailing list -- devel@xxxxxxxxxxxxxxxxxxxxxxx
To unsubscribe send an email to devel-leave@xxxxxxxxxxxxxxxxxxxxxxx
Fedora Code of Conduct: https://docs.fedoraproject.org/en-US/project/code-of-conduct/
List Guidelines: https://fedoraproject.org/wiki/Mailing_list_guidelines
List Archives: https://lists.fedoraproject.org/archives/list/devel@xxxxxxxxxxxxxxxxxxxxxxx
Do not reply to spam, report it: https://pagure.io/fedora-infrastructure/new_issue

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Fedora Announce]     [Fedora Users]     [Fedora Kernel]     [Fedora Testing]     [Fedora Formulas]     [Fedora PHP Devel]     [Kernel Development]     [Fedora Legacy]     [Fedora Maintainers]     [Fedora Desktop]     [PAM]     [Red Hat Development]     [Gimp]     [Yosemite News]

  Powered by Linux