]> git.ipfire.org Git - thirdparty/ccache.git/commitdiff
fix: Properly make unique temporary name in TRY_ASSIGN
authorJoel Rosdahl <joel@rosdahl.net>
Tue, 5 Aug 2025 08:48:18 +0000 (10:48 +0200)
committerJoel Rosdahl <joel@rosdahl.net>
Tue, 5 Aug 2025 09:01:04 +0000 (11:01 +0200)
src/ccache/util/expected.hpp

index 9f79ff95176b15f287cba36d78828892ce8f34f2..212b14c3abcf8da9d911d08d14fb3c8ccd23d7ca 100644 (file)
@@ -19,6 +19,7 @@
 #pragma once
 
 #include <ccache/util/format.hpp>
+#include <ccache/util/macro.hpp>
 
 #include <tl/expected.hpp>
 
@@ -59,11 +60,11 @@ void throw_on_error(const T& value, std::string_view prefix);
   } while (false)
 
 #define TRY_ASSIGN(var_, expression_)                                          \
-  auto result_##__LINE__##_ = (expression_);                                   \
-  if (!result_##__LINE__##_) {                                                 \
-    return tl::unexpected(std::move(result_##__LINE__##_.error()));            \
+  auto UNIQUE_VARNAME(_result_) = (expression_);                               \
+  if (!UNIQUE_VARNAME(_result_)) {                                             \
+    return tl::unexpected(std::move(UNIQUE_VARNAME(_result_).error()));        \
   }                                                                            \
-  var_ = std::move(*result_##__LINE__##_)
+  var_ = std::move(*UNIQUE_VARNAME(_result_))
 
 // --- Inline implementations ---