This is an archive of the discontinued LLVM Phabricator instance.

[flang] Remove default argument from function template specialization. NFC.
ClosedPublic

Authored by Meinersbur on Nov 16 2021, 1:59 PM.

Details

Summary

Patch D113697 added default function arguments to template specializations of ConvertToBinary.

According to https://en.cppreference.com/w/cpp/language/template_specialization this not allowed:

Default function arguments cannot be specified in explicit specializations of function templates, member function templates, and member functions of class templates when the class is implicitly instantiated.

It happens to compile with gcc, clang and msvc 14.30 (Visual Studio 2022), but not msvc 14.29 (Visual Studio 2020). Even for the compilers that syntactically accept it, the default argument will never be used (only the default argument of the template declaration). From https://en.cppreference.com/w/cpp/language/function_template

Note that only non-template and primary template overloads participate in overload resolution.

That is, the explicit function template specialization is not added to the overload candidate set. Only after all the parameter types are known, are the explicit specializations chosen, at which point the default function argument is ignored.

Also see D85657.

Diff Detail

Event Timeline

Meinersbur created this revision.Nov 16 2021, 1:59 PM
Meinersbur requested review of this revision.Nov 16 2021, 1:59 PM
Herald added a project: Restricted Project. · View Herald TranscriptNov 16 2021, 1:59 PM
klausler accepted this revision.Nov 16 2021, 2:13 PM
This revision is now accepted and ready to land.Nov 16 2021, 2:13 PM
Meinersbur edited the summary of this revision. (Show Details)Nov 16 2021, 2:35 PM