On 12/7/22 16:50, Patrick Palka wrote:
We currently declare __builtin_source_location with a const void* return
type instead of the true type (const std::source_location::__impl*), and
later when folding this builtin we just obtain the true type via name
lookup.

But the below testcase demonstrates this name lookup approach seems to
interact poorly with modules, since we may import an entity that uses
std::source_location::current() in a default argument (or DMI) without
also importing <source_location>, and thus the name lookup will fail
when folding the builtin at the call site unless we also import
<source_location>.

This patch fixes by instead initially declaring __builtin_source_location
with an auto return type and updating it appropriately upon its first use.
Thus when folding calls to this builtin we can fish out the true return
type through the type of the CALL_EXPR and avoid needing to do name
lookup.

That's a clever approach!  LGTM

nathan

--
Nathan Sidwell

Reply via email to