Skip to content

Undefined reference to index_tag<0ul> on clang 17 #54

Closed

Description

@nikhilkalige

clang above v17 throws an error during linking.

int main() {
    nonstd::variant< char, int, long, std::string > var;
    var =  'v' ;
    return 0;
}
/opt/compiler-explorer/gcc-13.2.0/lib/gcc/x86_64-linux-gnu/13.2.0/../../../../x86_64-linux-gnu/bin/ld: /tmp/example-480496.o:(.debug_addr+0x20): undefined reference to `void nonstd::variants::detail::index_tag<0ul>(nonstd::variants::detail::index_tag_t<0ul>)'

I compiled with clang 16 which works and compare the output of the object files from clang 17. The only different between the two is below

Clang-16 0000000000000000 W void nonstd::variants::detail::index_tag<0ul>(nonstd::variants::detail::index_tag_t<0ul>)
Clang-17                  U void nonstd::variants::detail::index_tag<0ul>(nonstd::variants::detail::index_tag_t<0ul>)

https://godbolt.org/z/fcY571qs7

Activity

  1. martinmoene commented on Sep 20, 2025

    @martinmoene
    Collaborator

    Thanks @nikhilkalige for your report.

    No idea yet how to tackle this.

  2. geghamyan commented on Sep 23, 2025

    @geghamyan

    Here is the PR that fixes the issue: #56
    I simplified the non-type template parameter by replacing the reference (which unfortunately generates an undefined reference) to a function with a pointer. Another option would be to use conditional compilation and apply the pointer only for Clang, but that seems like unnecessary complication. I also fixed the tests that were failing with GCC and Clang.

  3. geghamyan commented on Sep 23, 2025

    @geghamyan

    @martinmoene could you please check the result of script/generate_header.py? It looks like the output it generates is out of sync with the current implementation in template/variant.hpp. I suspect there were changes made to include/nonstd/variant.hpp, but the template was not updated accordingly.

  4. martinmoene commented on Sep 23, 2025

    @martinmoene
    Collaborator

    Thanks for your help. Hope to look into it later today / tonight.

  5. martinmoene commented on Sep 23, 2025

    @martinmoene
    Collaborator

    @nikhilkalige There is indeed one commit that changes include/nonstd/variant.hpp instead of template/variant.hpp.

    Clearly I forgot about the update script :(

    See also this remark at issue 55.

  6. geghamyan commented on Sep 23, 2025

    @geghamyan

    Sounds good, thank you. Please let me know if you'd like me to make any updates to the PR. Thank you for supporting this project.

  7. martinmoene commented on Sep 28, 2025

    @martinmoene
    Collaborator

    Merged PR #56.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions