interface: adjust getFileRef method detection for compatibility with gcc 4.9
authorSven Verdoolaege <sven.verdoolaege@gmail.com>
Sun, 26 Oct 2025 11:41:58 +0000 (26 12:41 +0100)
committerSven Verdoolaege <sven.verdoolaege@gmail.com>
Sat, 22 Nov 2025 14:26:18 +0000 (22 15:26 +0100)
Commit isl-0.26-152-g146c2f6aa8 (interface: update to removal of
SourceManager::createFileID(FileEntry*), Sat Jul 6 18:34:27 2024 +0200)
introduced a mechanism for detecting the presence of
the getFileRef method in FileManager that should be valid C++11,
but that apparently does not work in gcc 4.9.

Use a different mechanism that moreover checks for a specific overload
rather than just the presence of some getFileRef method.

Signed-off-by: Sven Verdoolaege <sven.verdoolaege@gmail.com>
interface/extract_interface.cc

index 79cb085..4ea7590 100644 (file)
@@ -374,18 +374,23 @@ static const FileEntry *ignore_error(const T obj)
        return ignore_error_helper(obj, 0, NULL);
 }
 
-/* This is identical to std::void_t in C++17.
- */
-template< class... >
-using void_t = void;
-
 /* A template class with value true if "T" has a getFileRef method.
  */
-template <class T, class = void>
-struct HasGetFileRef : public std::false_type {};
-template <class T>
-struct HasGetFileRef<T, ::void_t<decltype(&T::getFileRef)>> :
-    public std::true_type {};
+template <typename T>
+struct HasGetFileRef {
+private:
+    template <typename U>
+    static auto test(int) ->
+       decltype(std::declval<U>().
+           getFileRef(std::declval<const std::string &>()), std::true_type());
+
+    template <typename>
+    static std::false_type test(...);
+
+public:
+    using type = decltype(test<T>(0));
+    static constexpr bool value = type::value;
+};
 
 /* Return the FileEntryRef/FileEntry corresponding to the given file name or
  * an error if anything went wrong.