Skip to content

[clang] __has_unique_object_representations gives inconsistent answer based on instantiation order #95311

Closed
@ldionne

Description

@ldionne

The following code reports inconsistent results for __has_unique_object_representations:

template <int>
class Foo {
  int x;
};

static_assert(__has_unique_object_representations(Foo<0>[]));
static_assert(__has_unique_object_representations(Foo<0>[][3]));
static_assert(__has_unique_object_representations(Foo<0>));

The key here is that if you assert __has_unique_object_representations(Foo<0>) first, then everything works. So somehow asking for __has_unique_object_representations(Foo<0>) must cause something to be instantiated or stored in the AST and that changes the result of a subsequent __has_unique_object_representations(Foo<0>[]) query (notice the array).

This bug was extracted from this comment: #69241 (comment)

Godbolt: https://gcc.godbolt.org/z/Pb9ze7YxM

Metadata

Metadata

Assignees

No one assigned

    Labels

    clang:frontendLanguage frontend issues, e.g. anything involving "Sema"

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions