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

Enum in template not working with Clang #164

Closed
dominicpoeschko opened this issue Mar 11, 2022 · 3 comments
Closed

Enum in template not working with Clang #164

dominicpoeschko opened this issue Mar 11, 2022 · 3 comments
Labels
invalid This doesn't seem right

Comments

@dominicpoeschko
Copy link

Enums in templated structs do not work on Clang but do work in GCC

Works:
enum class E1{aa, bb};

Does not Work:

template<typename>
struct xx{
enum class E{aa, bb};
};

Godbold link with example

https://godbolt.org/z/x3e4rKT89

@schaumb
Copy link
Contributor

schaumb commented Mar 11, 2022

weird. It's probably a compiler optimization bug.

If you reference one of the enum value, the problem is gone.
https://godbolt.org/z/cj5b1ETxc

@schaumb
Copy link
Contributor

schaumb commented Mar 11, 2022

gcc works, only clang optimize out enum names:

template<typename T, T v>
auto n() {
    return std::string_view{__PRETTY_FUNCTION__};
}

std::cout << n<E2, static_cast<E2>(0)>();  // writes: auto n() [T = xx<int>::E, v = (xx<int>::E)0]

@Neargye Neargye added the invalid This doesn't seem right label Mar 11, 2022
@schaumb
Copy link
Contributor

schaumb commented Mar 14, 2022

I think it is a limitation because of the compiler optimization. It is need to mentioned on the Limitation page.

@Neargye Neargye added this to the 0.8.1 milestone May 10, 2022
@Neargye Neargye modified the milestones: 0.8.1, 0.8.2 Jun 28, 2022
@Neargye Neargye closed this as completed Jun 28, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
invalid This doesn't seem right
Projects
None yet
Development

No branches or pull requests

3 participants