diff --git a/llvm/include/llvm/ADT/Any.h b/llvm/include/llvm/ADT/Any.h index 0e2f587c7cba42..934dfc142d3761 100644 --- a/llvm/include/llvm/ADT/Any.h +++ b/llvm/include/llvm/ADT/Any.h @@ -31,9 +31,9 @@ class LLVM_EXTERNAL_VISIBILITY Any { // identifier for the type `T`. It is explicitly marked with default // visibility so that when `-fvisibility=hidden` is used, the loader still // merges duplicate definitions across DSO boundaries. - template struct TypeId { - static const char Id; - }; + // We also cannot mark it as `const`, otherwise msvc merges all definitions + // when lto is enabled, making any comparison return true. + template struct TypeId { static char Id; }; struct StorageBase { virtual ~StorageBase() = default; @@ -117,7 +117,7 @@ class LLVM_EXTERNAL_VISIBILITY Any { std::unique_ptr Storage; }; -template const char Any::TypeId::Id = 0; +template char Any::TypeId::Id = 0; template bool any_isa(const Any &Value) { if (!Value.Storage)