[flang-commits] [flang] d2124bf - [flang] Remove default argument from function template specialization. NFC.

Michael Kruse via flang-commits flang-commits at lists.llvm.org
Tue Nov 16 22:06:32 PST 2021


Author: Michael Kruse
Date: 2021-11-17T00:05:34-06:00
New Revision: d2124bfccf5982f5fa0f9b2c2253fc0bb65beb4c

URL: https://github.com/llvm/llvm-project/commit/d2124bfccf5982f5fa0f9b2c2253fc0bb65beb4c
DIFF: https://github.com/llvm/llvm-project/commit/d2124bfccf5982f5fa0f9b2c2253fc0bb65beb4c.diff

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

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.

Reviewed By: klausler

Differential Revision: https://reviews.llvm.org/D114032

Added: 
    

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

Removed: 
    


################################################################################
diff  --git a/flang/include/flang/Decimal/decimal.h b/flang/include/flang/Decimal/decimal.h
index 45d60d8eedb87..b9ac6b71cd03a 100644
--- a/flang/include/flang/Decimal/decimal.h
+++ b/flang/include/flang/Decimal/decimal.h
@@ -105,17 +105,17 @@ ConversionToBinaryResult<PREC> ConvertToBinary(const char *&,
     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


        


More information about the flang-commits mailing list