Correct me, if I am wrong, but I think it is legal C++ (no ODR violation), if different translation units declare a function with different default arguments?
The rule is probably (currently) more strict for the template type.
(And how about default template arguments?)
The default function arguments are kind of "after the declaration". How to interpret the call.
Perhaps it can be done similarly for the derived template type.
On the other hand default function arguments lead to various problems.
And perhaps would be done differently today.
Those should be considered, before extending their functionality.
-----Ursprüngliche Nachricht-----
Von: shyeyian via Std-Proposals <std-proposals@lists.isocpp.org>
Gesendet: Fr 18.09.2026 09:04
Betreff: [std-proposals] Should a default argument provide the default template type?
An: std-proposals@lists.isocpp.org;
CC: shyeyian@gmail.com;
Consider this declaration:```cppvoid func(auto&& arg = 42);int main(){func();}```Both gcc and clang reject the call:```text[shyeyian@core cppmake]$ g++ -std=c++26 test/main.cpptest/main.cpp: In function 'int main()':test/main.cpp:5:9: error: no matching function for call to 'func()'5 | func();| ~~~~^~* there is 1 candidate* candidate 1: 'template<class auto:1> void func(auto:1&&)'test/main.cpp:1:6:1 | void func(auto&& arg = 1);| ^~~~* template argument deduction/substitution failed:* couldn't deduce template parameter 'auto:1'test/main.cpp:5:9:5 | func();| ~~~~^~[shyeyian@core cppmake]$ clang++ -std=c++26 test/main.cpptest/main.cpp:5:5: error: no matching function for call to 'func'5 | func();| ^~~~test/main.cpp:1:6: note: candidate template ignored: couldn't infer template argument 'arg:auto'1 | void func(auto&& arg = 1);| ^1 error generated.[shyeyian@core cppmake]$```This follows from the current rules: the declaration is an abbreviated function template. In other words, it is effectively equivalent to:```cpptemplate<class T>void func(T&& arg = 42);```But the declaration already contains a default expression with a known type! I hope the declaration to be equivalent to```cpptemplate<class T = decltype(42)>void func(T&& arg = 42);```This would make `func()` well-formed without changing calls that supply an argument. In those calls, ordinary template argument deduction would still determine `T`; the default template argument would be used only when deduction does not provide one.What do you think of this behavior? Are there any compatibility concerns I may have overlooked?-- Std-Proposals mailing list Std-Proposals@lists.isocpp.org https://lists.isocpp.org/mailman/listinfo.cgi/std-proposals