[PATCH] D114032: [flang] Remove default argument from function template specialization. NFC.

Michael Kruse via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Nov 16 13:59:58 PST 2021


Meinersbur created this revision.
Meinersbur added reviewers: mehdi_amini, klausler.
Meinersbur added a project: Flang.
Herald added a subscriber: jdoerfert.
Meinersbur requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

Patch D113697 <https://reviews.llvm.org/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 except 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 <https://reviews.llvm.org/D85657>.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D114032

Files:
  flang/include/flang/Decimal/decimal.h


Index: flang/include/flang/Decimal/decimal.h
===================================================================
--- flang/include/flang/Decimal/decimal.h
+++ flang/include/flang/Decimal/decimal.h
@@ -105,17 +105,17 @@
     enum FortranRounding = RoundNearest, const char *end = nullptr);
 
 extern template ConversionToBinaryResult<8> ConvertToBinary<8>(
-    const char *&, enum FortranRounding, const char *end = nullptr);
+    const char *&, enum FortranRounding, const char *end);
 extern template ConversionToBinaryResult<11> ConvertToBinary<11>(
-    const char *&, enum FortranRounding, const char *end = nullptr);
+    const char *&, enum FortranRounding, const char *end);
 extern template ConversionToBinaryResult<24> ConvertToBinary<24>(
-    const char *&, enum FortranRounding, const char *end = nullptr);
+    const char *&, enum FortranRounding, const char *end);
 extern template ConversionToBinaryResult<53> ConvertToBinary<53>(
-    const char *&, enum FortranRounding, const char *end = nullptr);
+    const char *&, enum FortranRounding, const char *end);
 extern template ConversionToBinaryResult<64> ConvertToBinary<64>(
-    const char *&, enum FortranRounding, const char *end = nullptr);
+    const char *&, enum FortranRounding, const char *end);
 extern template ConversionToBinaryResult<113> ConvertToBinary<113>(
-    const char *&, enum FortranRounding, const char *end = nullptr);
+    const char *&, enum FortranRounding, const char *end);
 } // namespace Fortran::decimal
 extern "C" {
 #define NS(x) Fortran::decimal::x


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D114032.387733.patch
Type: text/x-patch
Size: 1555 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20211116/2b9e2c80/attachment.bin>


More information about the llvm-commits mailing list