Repository navigation
Description
Discussed in #482
Originally posted by jakub-labenski November 5, 2026
Issue Summary
A class template's default template argument can be looked up in the wrong context. This happens when the default argument is filled in while the front end matches a partial specialization of a different template. Names in the default argument are then looked up from where that partial specialization is declared, instead of where the class template is declared. Anything declared after the partial specialization is not found, and the substitution is wrongly treated as failing.
In practice this breaks the common void_t detection idiom: the "is this well-formed" trait quietly returns false. Nothing is diagnosed at the point of the mistake, so the result is a wrong static_assert result or the wrong overload being chosen. The code compiles with GCC, Clang and MSVC.
Reproducing Source Code
template<class...> using void_t = void;
template<class, template<class...> class TT, class... P>
constexpr bool ok = false;
template<template<class...> class TT, class... P>
constexpr bool ok<void_t<TT<P...>>, TT, P...> = true;
namespace lib { template<class T> T&& declval() noexcept; }
template<class T, class = decltype(&lib::declval<T&>())> struct A {};
struct V {};
static_assert(ok<void, A, V>, "substitution wrongly reported as failing");Command-line Options
cpfe --c++17 repro.cpp
Type of Issue
[Front End] This code SHOULD compile with these options.
Additional Details
Actual output:
"repro.cpp", line 15: error: static assertion failed with
"substitution wrongly reported as failing"
static_assert(ok<void, A, V>, "substitution wrongly reported as failing");
Observations:
- It also reproduces with
--c++14,--g++and--clang. - It does not reproduce in the default Microsoft mode (
--microsoft). That mode turns off dependent name processing, so names in templates are looked up later, when the template is used. It does reproduce with--microsoft --dep_name. - Moving
namespace libabove the partial specialization ofokmakes the code compile, so the bug depends on declaration order. A<V>itself can be used directly with no problem. The failure only happens whenA's default argument is filled in while theok<void_t<TT<P...>>, TT, P...>partial specialization is being matched.- Class template partial specializations (
struct is_detected<void_t<...>, ...>) behave the same way.
Reproducing (Standard) Configuration(s)
linux-gcc-debug
Reproducing (Non-standard) Configuration
No response
I acknowledge that:
- I have checked open issues and existing discussions before filing this report.
- The reproducing source code that I have provided does not depend on headers that I have not included with my submission.
- I have reduced the reproducing source code to the best of my ability.
- I have selected at least one standard configuration or uploaded a non-standard configuration dump.
- I understand code shared via this form is NOT confidential.
- I have permission to share the reproducing source code and grant permission for the project to use the source code (or derivatives of the source code) to create tests.
- I agree that any tests created using the reproducing source code (or deriatives of it) will be licensed under project license unless I included a
LICENSE.txtfile in my.zipor.tar.gzupload. If I included aLICENSE.txtfile, any tests created using the reproducing source code will be governed by the terms of the license I provided instead.
Activity
Lookup in default template arguments during partial specialization re…
Lookup in default template arguments during partial specialization re…
Lookup in default template arguments during partial specialization re…
Lookup in default template arguments during partial specialization re…
Sync upstream main (ad4cfc4) into multibackend and reconcile build/ho…
Sync gcc_backend with upstream main (ad4cfc4) and reconcile build/IL …