[PATCH] D51490: [Error] Fix template deduction in createFileError

Alexandre Ganea via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Aug 30 08:07:01 PDT 2018


aganea created this revision.
aganea added reviewers: zturner, ilya-biryukov.
Herald added a subscriber: llvm-commits.

This properly fixes the build break here <http://lab.llvm.org:8011/builders/lld-perf-testsuite/builds/6601/steps/build-bin%2Flld/logs/stdio>.

  /home/buildslave/slave_as-bldslv8/lld-perf-testsuite/llvm/include/llvm/Support/Error.h:1219:11: error: default arguments cannot be added to a function template that has already been declared
          * = nullptr) {
            ^ ~~~~~~~
  /home/buildslave/slave_as-bldslv8/lld-perf-testsuite/llvm/include/llvm/Support/Error.h:1175:16: note: previous template declaration is here
    friend Error createFileError(
                 ^
  1 error generated.

As an example, I've included a compile-time error in `ErrorTest.cpp` (which I would not commit), although I don't know how I should test this properly?

On a broader view, do you think shielding `createFileError()` against such usage is useful? It is a corner case, and it is already covered at runtime.


Repository:
  rL LLVM

https://reviews.llvm.org/D51490

Files:
  include/llvm/Support/Error.h
  unittests/Support/ErrorTest.cpp


Index: unittests/Support/ErrorTest.cpp
===================================================================
--- unittests/Support/ErrorTest.cpp
+++ unittests/Support/ErrorTest.cpp
@@ -874,6 +874,8 @@
       },
       "");
 #endif
+  consumeError(createFileError("file.bin", Error::success()));
+
   Error E1 = make_error<CustomError>(1);
   Error FE1 = createFileError("file.bin", std::move(E1));
   EXPECT_EQ(toString(std::move(FE1)).compare("'file.bin': CustomError {1}"), 0);
Index: include/llvm/Support/Error.h
===================================================================
--- include/llvm/Support/Error.h
+++ include/llvm/Support/Error.h
@@ -1171,7 +1171,7 @@
 /// show more detailed information to the user.
 class FileError final : public ErrorInfo<FileError> {
 
-  template <class Err>
+  template <class Err, typename>
   friend Error createFileError(std::string, Err);
 
 public:
@@ -1207,7 +1207,10 @@
 
 /// Concatenate a source file path and/or name with an Error. The resulting
 /// Error is unchecked.
-template <class Err>
+template <class Err, typename = typename std::enable_if<
+                         std::is_base_of<Error, Err>::value &&
+                             !std::is_base_of<ErrorSuccess, Err>::value,
+                         Err>::type>
 inline Error createFileError(std::string F, Err E) {
   return FileError::build(F, std::move(E));
 }


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D51490.163333.patch
Type: text/x-patch
Size: 1381 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20180830/3e3eaede/attachment.bin>


More information about the llvm-commits mailing list