llvm / llvm/llvm-project

[clang] Clang accepts explicit instantiation of a function template with deduced return type and explicit trailing return type (non‑standard)

Open
#164,398 1 comment 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

I suspect that **Clang currently accepts a non‑standard form of explicit instantiation** that other major compilers (GCC, MSVC, EDG) correctly reject:

```cpp
struct A {
char g() { return 'a'; }
template auto f(T t) {
return t + g();
}
};

template auto A::f(int t) -> decltype(t + g());
// The correct code should probably be:
// template auto A::f(int t);
```

https://godbolt.org/z/cdz4Y3Tea

What’s puzzling is the version history:

- **Clang ≤ 16.0.0** correctly rejected this code.
- **Clang 17.0.1 – 18.1.0** caused a **crash**.
- **Clang 19.1.0+** now **accepts** the code silently.

It would be helpful to know **which change or patch introduced this behavior**,
and whether the current acceptance is intentional or a missing diagnostic.

Contributor guide

Open the contributing guide

Research direction

Start with the reduced C++ reproducer in the issue and verify its behavior across the listed Clang versions. Bisect the change between Clang 16 and 19 that altered rejection or crashing into acceptance, then check whether the current behavior matches the standard and add or update a regression test with the expected diagnostic.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp
Domain
compilers
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
38/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.