<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/107642>107642</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
Incorrect deduplication of member of anonymous namespace in clang++17, clang++18
</td>
</tr>
<tr>
<th>Labels</th>
<td>
clang
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
mgibson-antithesis
</td>
</tr>
</table>
<pre>
The following compiles and links correctly with clang++16:
```c++
// header.h
#pragma once
#include <array>
#include <iostream>
struct Printer {
const char* message;
Printer(const char* message) : message(message) { }
void print_stuff() {
std::cout << message << std::endl;
}
};
namespace { // Anonymous namespace which is translation-unit-specific; certain symbols aren't exposed in the symbol table as a result
template <std::size_t N>
struct fixed_string {
std::array<char, N> contents;
constexpr fixed_string( const char (&arr)[N] )
{
for(unsigned int i=0; i<N; i++) contents[i] = arr[i];
}
const char* c_str() const { return contents.data(); }
};
template <fixed_string message>
struct Entry {
[[clang::always_inline]] static inline Printer create() {
return Printer(message.c_str());
}
static inline Printer printer = create();
};
}
#define TEST(message) \
Entry< \
fixed_string(message) \
>::printer.print_stuff()
```
```c++
// foo.cpp
#include "header.h"
void foo()
{
TEST("Same name");
}
```
```c++
// bar.cpp
#include <iostream>
#include "header.h"
void bar()
{
TEST("Same name");
}
int main(int argc, char** argv) {
std::cout << "Hello, world" << std::endl;
return 0;
}
```
Command line is:
```bash
$ clang++ --std=c++20 bar.cpp foo.cpp
`.rodata._ZTAXtlN12_GLOBAL__N_112fixed_stringILm10EEEtlSt5arrayIcLm10EEtlA10_cLc83ELc97ELc109ELc101ELc32ELc110ELc97ELc109ELc101EEEEE' referenced in section `.data' of /run/user/1000/foo-70e9c4.o: defined in discarded section `.rodata._ZTAXtlN12_GLOBAL__N_112fixed_stringILm10EEEtlSt5arrayIcLm10EEtlA10_cLc83ELc97ELc109ELc101ELc32ELc110ELc97ELc109ELc101EEEEE[_ZTAXtlN12_GLOBAL__N_112fixed_stringILm10EEEtlSt5arrayIcLm10EEtlA10_cLc83ELc97ELc109ELc101ELc32ELc110ELc97ELc109ELc101EEEEE]' of /run/user/1000/foo-70e9c4.o
clang++: error: linker command failed with exit code 1 (use -v to see invocation)
```
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJzMVkuv6jgS_jVmUwIlDhCyYMFz5krozEj3LEazQY5TAXc7dmQ75xz617fsBBIerb5XaqnbQsbxo971VTFrxUkhLslsTWbbEWvcWZtldRK51WrMlBPujFbYUa6Ly_L9jFBqKfWnUCfguqqFRAtMFSCF-tUC18Ygd_ICn8KdgUumToSuCV3Hc5KsSLQl0XWeR-2Ptxe6XbondA9nZAWayfm6mdSGnSoGWnG8I0ITobhsCgSSbJgx7EKS3aszoa0zyKr-OMzWmYY7-K8RyqEBknZyAABwrawDfmaG0BVUaC07IUnWw_fXl4QuXl-nGZBk8LkYHqRrIOn2jh4AfGhRQO3pHq1rypLQRXe7v-OHdYW3abLiunFeR5Jsroyun7c7qAp5k33ANd0-aKRYhbZmHFvxWn-slFaXSjcW-uPPs-BnEBacYcpK5oRW40YJN7Y1clEKTpI1cDSOCQX2UuVaWmAGFaGpA_yqtcUChAJ3xu4cHMslArPAwKBtpOtVdljVkrmg2k0tK37Do4O3m1tbwwSnluILi6N1xgdrb73b2y5cNq3LNoGId7pD5Wxvq24E9-JXbe7oEroYxAkEV82ZMYRmZLZ-I7Mt-OUdpSdH-lFqH0ONCvnoreJAkGQbeRsKkmze2kWbKjTr5ZytReCSbMHzbT-fpH8RZs8hzr1SXbS1Jz4EDLrGqBvDScEcay95kW6Er1we8uPBcXc-uaXUs-92ypnLs6UCTK1bWGl9KD_ZxR6FkkKhV3y2BeuYExzavVtqc4PM4R_lkh-don1Gd_JNBnZptX7Kooe8fMW_vkJMsr2T5Z7czXr3pAlNCiw9uffd9_cHFJltev7Bbj7x-92HcH350rsg2LOTcvIEPw-g_cNIXmo94XX9DMmU3kCe0iG5AH-l1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