[llvm] ad38c39 - [Support][NFC] Drop unnecessary default lambdas (#175577)

via llvm-commits llvm-commits at lists.llvm.org
Mon Jan 12 09:01:48 PST 2026


Author: Alexis Engelke
Date: 2026-01-12T17:01:44Z
New Revision: ad38c3987f8ecee618c46202173360cbc89f2021

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

LOG: [Support][NFC] Drop unnecessary default lambdas (#175577)

These lambdas must be instantiated and code-generated in multiple CUs;
instead use the null/default state of std::function as default state.

Very minor compile-time improvement of Clang/LLVM.

Added: 
    

Modified: 
    llvm/include/llvm/Support/CommandLine.h

Removed: 
    


################################################################################
diff  --git a/llvm/include/llvm/Support/CommandLine.h b/llvm/include/llvm/Support/CommandLine.h
index 5355b90eb19b3..be754f3c159ca 100644
--- a/llvm/include/llvm/Support/CommandLine.h
+++ b/llvm/include/llvm/Support/CommandLine.h
@@ -1462,7 +1462,8 @@ class opt
       return true; // Parse error!
     this->setValue(Val);
     this->setPosition(pos);
-    Callback(Val);
+    if (Callback)
+      Callback(Val);
     return false;
   }
 
@@ -1517,13 +1518,15 @@ class opt
 
   template <class T> DataType &operator=(const T &Val) {
     this->setValue(Val);
-    Callback(Val);
+    if (Callback)
+      Callback(Val);
     return this->getValue();
   }
 
   template <class T> DataType &operator=(T &&Val) {
     this->getValue() = std::forward<T>(Val);
-    Callback(this->getValue());
+    if (Callback)
+      Callback(this->getValue());
     return this->getValue();
   }
 
@@ -1539,8 +1542,7 @@ class opt
     Callback = CB;
   }
 
-  std::function<void(const typename ParserClass::parser_data_type &)> Callback =
-      [](const typename ParserClass::parser_data_type &) {};
+  std::function<void(const typename ParserClass::parser_data_type &)> Callback;
 };
 
 #if !(defined(LLVM_ENABLE_LLVM_EXPORT_ANNOTATIONS) && defined(_MSC_VER))
@@ -1717,7 +1719,8 @@ class list : public Option, public list_storage<DataType, StorageClass> {
     list_storage<DataType, StorageClass>::addValue(Val);
     setPosition(pos);
     Positions.push_back(pos);
-    Callback(Val);
+    if (Callback)
+      Callback(Val);
     return false;
   }
 
@@ -1786,8 +1789,7 @@ class list : public Option, public list_storage<DataType, StorageClass> {
     Callback = CB;
   }
 
-  std::function<void(const typename ParserClass::parser_data_type &)> Callback =
-      [](const typename ParserClass::parser_data_type &) {};
+  std::function<void(const typename ParserClass::parser_data_type &)> Callback;
 };
 
 // Modifier to set the number of additional values.
@@ -1894,7 +1896,8 @@ class bits : public Option, public bits_storage<DataType, Storage> {
     this->addValue(Val);
     setPosition(pos);
     Positions.push_back(pos);
-    Callback(Val);
+    if (Callback)
+      Callback(Val);
     return false;
   }
 
@@ -1942,8 +1945,7 @@ class bits : public Option, public bits_storage<DataType, Storage> {
     Callback = CB;
   }
 
-  std::function<void(const typename ParserClass::parser_data_type &)> Callback =
-      [](const typename ParserClass::parser_data_type &) {};
+  std::function<void(const typename ParserClass::parser_data_type &)> Callback;
 };
 
 //===----------------------------------------------------------------------===//


        


More information about the llvm-commits mailing list