llvm / llvm/llvm-project

visibility of template functions during subsitution and std::tuple

Open
#181,530 4 comments 0 reactions 0 assignees View on GitHub
clang:frontend diverges-from:edg diverges-from:gcc diverges-from:msvc
Dominant language
LLVM
Stars
40.5k
Forks
18.7k
PR merge metrics
PR metrics pending

Description

The following code compiles in clang but not gcc or msvc. It appears that when gcc or msvc fails, it is because the forward declaration don't cause all of the definitions of foo to be visible while evaluating `decltype`. Clang evaluates the `decltype` after the forward declarations. Given that gcc fails with `std::tuple` but not a custom type suggests that maybe gcc has a bug, but I don't want to report the bug to multiple projects until someone more knowledgeable of the spec confirms what the behaviour is supposed to be.

https://godbolt.org/z/e5oG6Gcn9
```c++
#include

//declare the templates
constexpr int foo(int a);

template class T, class Td>
constexpr T()))>
foo(T a);

//----- then define them
constexpr int foo(int a);

template class T, class Td>
constexpr T()))>
foo(T a){return {};};

template struct A {};
template struct my_tuple{};

int main() {
foo(A>{}); //this works in gcc for some reason (msvc fails)
foo(A>{}); //this fails in gcc
return 0;
}
```

Contributor guide

Open the contributing guide

Research direction

Start with the minimized example in the issue and reproduce it using the linked Compiler Explorer case. Compare clang, GCC, and MSVC results for the std::tuple and my_tuple calls, then consult the relevant C++ rules for template substitution, forward declarations, and decltype. Done means establishing the expected behavior and documenting whether an LLVM change or a report to another compiler is appropriate.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp
Domain
compilers
Issue type
Bug
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.