https://gcc.gnu.org/bugzilla/show_bug.cgi?id=123443

            Bug ID: 123443
           Summary: mangling of unnamed enum inside an exported class
           Product: gcc
           Version: 16.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: zhixu.liu at gmail dot com
  Target Milestone: ---

https://bugs.gentoo.org/967872#c9

Different symbols are produced by gcc and clang because this is an unnamed enum
introduced via a using alias inside an exported class.

I am not sure whether this behavior is implementation-defined by the ABI
specification (see Itanium C++ ABI, “Named Types” mangling rules:
https://itanium-cxx-abi.github.io/cxx-abi/abi.html#mangling.named).

see following for the test case copied:

::::::::::::::
test.h
::::::::::::::
#pragma once

#if defined(BUILDING_LIB)
# define API __attribute__((visibility("default")))
#else
# define API
#endif

namespace N {
        class API Url {
                public:
                        using Scope = enum {
                                Base,
                                One,
                                Sub
                        };
        };

        class API Server {
                public:
                        void setScope(Url::Scope scope);
        };
}
::::::::::::::
lib.cpp
::::::::::::::
#define BUILDING_LIB
#include "test.h"

namespace N {
        void Server::setScope(Url::Scope) { }
}
::::::::::::::
test.sh
::::::::::::::
#!/bin/bash

CXXS="g++-11"
CXXS+=" g++-12"
CXXS+=" g++-13"
CXXS+=" g++-14"
CXXS+=" g++-15"
CXXS+=" g++-16"
CXXS+=" clang++-16"
CXXS+=" clang++-17"
CXXS+=" clang++-18"
CXXS+=" clang++-19"
CXXS+=" clang++-20"
CXXS+=" clang++-21"

for CXX in ${CXXS}; do
        echo ">> ${CXX}"
        ${CXX} -fPIC -shared -fvisibility=hidden lib.cpp -o libtest.so
        nm -C libtest.so | grep setScope
done

 # bash test.sh
>> g++-11
00000000000010fa T N::Server::setScope(N::Url::{unnamed type#1})
>> g++-12
00000000000010fa T N::Server::setScope(N::Url::{unnamed type#1})
>> g++-13
00000000000010fa T N::Server::setScope(N::Url::{unnamed type#1})
>> g++-14
00000000000010fa T N::Server::setScope(N::Url::{unnamed type#1})
>> g++-15
00000000000010fa T N::Server::setScope(N::Url::{unnamed type#1})
>> g++-16
00000000000010fa T N::Server::setScope(N::Url::{unnamed type#1})
>> clang++-16
0000000000001100 T N::Server::setScope(N::Url::Scope)
>> clang++-17
0000000000001100 T N::Server::setScope(N::Url::Scope)
>> clang++-18
0000000000001100 T N::Server::setScope(N::Url::Scope)
>> clang++-19
0000000000001100 T N::Server::setScope(N::Url::Scope)
>> clang++-20
0000000000001100 T N::Server::setScope(N::Url::Scope)
>> clang++-21
0000000000001100 T N::Server::setScope(N::Url::Scope)

Reply via email to