llvm / llvm-project

The LLVM Project is a collection of modular and reusable compiler and toolchain technologies.
http://llvm.org
Other
27.92k stars 11.52k forks source link

Method Constraints with Full Specialization Fails to Link (Undefined Symbols) #103475

Open jcsq6 opened 1 month ago

jcsq6 commented 1 month ago

Please refer to this previous issue I posted, as the problem is very related. This issue was resolved, as it appeared to be fixed in the most recent clang version. However, it is still causing problems with the linker.

I can only assume that the problem stems from how the symbols are named by clang, and that the full specialization of a method with constraints is being named inconsistently between the declaration and implementation.

This inconsistency also appears to only present itself in between different translation units.

Minimal example of failure: To compile: clang++ -std=c++20 -c fail.cpp -o fail.o clang++ -std=c++20 fail.o main.cpp

fail.h

#pragma once
#include <concepts>

template <typename T>
struct test
{
    void method() requires(std::floating_point<T>);
};

fail.cpp

#include "fail.h"
#include <iostream>

template <>
void test<double>::method()
{
    std::cout << "Sucess\n";
}

main.cpp

#include <iostream>
#include "fail.h"

int main()
{
    test<double> t;
    t.method();
}

This compiles and links in gcc, but fails to compile using clang.

clang++ --version
clang version 20.0.0git (https://github.com/llvm/llvm-project.git 101cf540e698529d3dd899d00111bcb654a3c12b)
Target: arm64-apple-darwin23.5.0
Thread model: posix
InstalledDir: /usr/local/bin

PS: Although I wasn't able to replicate this by adding "-g" to this minimal example, this problem only presented itself in the release build of my project.

EDIT: Here's the output:

Undefined symbols for architecture arm64:
  "test<double>::method() requires std::floating_point<T>", referenced from:
      _main in main-2929fe.o
ld: symbol(s) not found for architecture arm64
llvmbot commented 1 month ago

@llvm/issue-subscribers-clang-codegen

Author: JC Squires (jcsq6)

Please refer to [this](https://github.com/llvm/llvm-project/issues/102548) previous issue I posted, as the problem is very related. This issue was resolved, as it appeared to be fixed in the most recent clang version. However, it is still causing problems with the linker. I can only assume that the problem stems from how the symbols are named by clang, and that the full specialization of a method with constraints is being named inconsistently between the declaration and implementation. This inconsistency also appears to only present itself in between different translation units. Minimal example of failure: To compile: `clang++ -std=c++20 -c fail.cpp -o fail.o` `clang++ -std=c++20 fail.o main.cpp` **fail.h** ``` #pragma once #include <concepts> template <typename T> struct test { void method() requires(std::floating_point<T>); }; ``` **fail.cpp** ``` #include "fail.h" #include <iostream> template <> void test<double>::method() { std::cout << "Sucess\n"; } ``` **main.cpp** ``` #include <iostream> #include "fail.h" int main() { test<double> t; t.method(); } ``` This compiles and links in gcc, but fails to compile using clang. ``` clang++ --version clang version 20.0.0git (https://github.com/llvm/llvm-project.git 101cf540e698529d3dd899d00111bcb654a3c12b) Target: arm64-apple-darwin23.5.0 Thread model: posix InstalledDir: /usr/local/bin ``` PS: Although I wasn't able to replicate this by adding "-g" to this minimal example, this problem only presented itself in the release build of my project. EDIT: Here's the output: ``` Undefined symbols for architecture arm64: "test<double>::method() requires std::floating_point<T>", referenced from: _main in main-2929fe.o ld: symbol(s) not found for architecture arm64 ```
llvmbot commented 1 month ago

@llvm/issue-subscribers-c-20

Author: JC Squires (jcsq6)

Please refer to [this](https://github.com/llvm/llvm-project/issues/102548) previous issue I posted, as the problem is very related. This issue was resolved, as it appeared to be fixed in the most recent clang version. However, it is still causing problems with the linker. I can only assume that the problem stems from how the symbols are named by clang, and that the full specialization of a method with constraints is being named inconsistently between the declaration and implementation. This inconsistency also appears to only present itself in between different translation units. Minimal example of failure: To compile: `clang++ -std=c++20 -c fail.cpp -o fail.o` `clang++ -std=c++20 fail.o main.cpp` **fail.h** ``` #pragma once #include <concepts> template <typename T> struct test { void method() requires(std::floating_point<T>); }; ``` **fail.cpp** ``` #include "fail.h" #include <iostream> template <> void test<double>::method() { std::cout << "Sucess\n"; } ``` **main.cpp** ``` #include <iostream> #include "fail.h" int main() { test<double> t; t.method(); } ``` This compiles and links in gcc, but fails to compile using clang. ``` clang++ --version clang version 20.0.0git (https://github.com/llvm/llvm-project.git 101cf540e698529d3dd899d00111bcb654a3c12b) Target: arm64-apple-darwin23.5.0 Thread model: posix InstalledDir: /usr/local/bin ``` PS: Although I wasn't able to replicate this by adding "-g" to this minimal example, this problem only presented itself in the release build of my project. EDIT: Here's the output: ``` Undefined symbols for architecture arm64: "test<double>::method() requires std::floating_point<T>", referenced from: _main in main-2929fe.o ld: symbol(s) not found for architecture arm64 ```