Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

clang-19 returns true for __is_literal_type on union with non trivial member starting with C++-23 #85550

Open
AMS21 opened this issue Mar 16, 2024 · 6 comments
Labels
clang:frontend Language frontend issues, e.g. anything involving "Sema"

Comments

@AMS21
Copy link
Contributor

AMS21 commented Mar 16, 2024

Given the following code

struct non_trivial {
    ~non_trivial();
};

union non_trivial_union {
    int i;
    non_trivial n;
};

static_assert(!__is_literal_type(non_trivial), "");
static_assert(!__is_literal_type(non_trivial_union), "");

clang-18.1.0 compiles fine while clang-19 fails the second static_assert.

godbolt

Note that this does not happen in C++-20 mode godbolt

@Sirraide Sirraide added clang:frontend Language frontend issues, e.g. anything involving "Sema" and removed new issue labels Mar 16, 2024
@llvmbot
Copy link
Collaborator

llvmbot commented Mar 16, 2024

@llvm/issue-subscribers-clang-frontend

Author: None (AMS21)

Given the following code
struct non_trivial {
    ~non_trivial();
};

union non_trivial_union {
    int i;
    non_trivial n;
};

static_assert(!__is_literal_type(non_trivial), "");
static_assert(!__is_literal_type(non_trivial_union), "");

clang-18.1.0 compiles fine while clang-19 fails the second static_assert.

godbolt

Note that this does not happen in C++-20 mode godbolt

@Sirraide
Copy link
Contributor

This is a bit strange. Afaik a union is literal if it contains at least one literal nsdm (provided there is no other reason for it to be non-literal). It is a bit strange that the result is different in C++23 and C++20 though.

CC @zygoloid @shafik

@AMS21
Copy link
Contributor Author

AMS21 commented Mar 18, 2024

Just took another look at my test code and there seems to be a lot of disagreement if this type is literal or not.

gcc before 10.0 says it's always: not literal
gcc since 10.0 says it's literal starting with C++-20
MSVC 2019/2022 say it's literal starting with C++-17

With that and the fact that is_literal_type was removed in C++-20 feel free to close as won't fix.

@AMS21 AMS21 changed the title clang-19 returns true for __is_literal_type on union with non trivial member with C++-23+ clang-19 returns true for __is_literal_type on union with non trivial member starting with C++-23 Mar 18, 2024
@frederick-vs-ja
Copy link
Contributor

Seems related to #77753. The implicitly declared destructor of non_trivial_union is non-trivial and deleted. IIUC non_trivial_union becomes a literal type since C++20.

@Sirraide
Copy link
Contributor

Sirraide commented Mar 18, 2024

With that and the fact that is_literal_type was removed in C++-20 feel free to close as won't fix.

That would explain the discrepancy, yeah. I’d leave the issue open in case I either misread the standard and the type is in fact not supposed to be literal (because we currently think it is, except in C++23 mode, apparently) or in case we do decide to do something about this.

@Fznamznon
Copy link
Contributor

I think it works as expected in C++23 mode. Union with at least one literal member is literal. The fact why it is not considered literal by clang in C++20 mode is the destructor. If a class doesn't have a constexpr destructor then it is not literal. Before C++23 clang takes into account destructors for all members of a class to decide that its destructor is constexpr (i.e. for destructor of a class to be constexpr, destructors of all of its members should be constexpr). I also double checked that union is a class https://eel.is/c++draft/class.union#general-1 , so this all worked for unions in pre C++23 too. non_trivial_union has constexpr destructor only after C++23 since its members don't matter anymore, hence the outcome.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
clang:frontend Language frontend issues, e.g. anything involving "Sema"
Projects
None yet
Development

No branches or pull requests

5 participants