diff --git a/CodeGenerator.cpp b/CodeGenerator.cpp index 52ecd8fb..02de8670 100644 --- a/CodeGenerator.cpp +++ b/CodeGenerator.cpp @@ -696,7 +696,7 @@ void CodeGenerator::InsertArg(const CXXTypeidExpr* stmt) mOutputFormatHelper.Append(kwTypeId); WrapInParens([&]() { if(stmt->isTypeOperand()) { - mOutputFormatHelper.Append(GetName(stmt->getType())); + mOutputFormatHelper.Append(GetName(stmt->getTypeOperand(const_cast(GetGlobalAST())))); } else { InsertArg(stmt->getExprOperand()); } diff --git a/tests/Issue522.cpp b/tests/Issue522.cpp new file mode 100644 index 00000000..55bc1129 --- /dev/null +++ b/tests/Issue522.cpp @@ -0,0 +1,3 @@ +#include +std::type_info const& tiA = typeid(int); +std::type_info const& tiB = typeid(0); diff --git a/tests/Issue522.expect b/tests/Issue522.expect new file mode 100644 index 00000000..6d7207fd --- /dev/null +++ b/tests/Issue522.expect @@ -0,0 +1,5 @@ +#include +const std::type_info & tiA = typeid(int); + +const std::type_info & tiB = typeid(0); + diff --git a/tests/TypeIdInTemplateTest.expect b/tests/TypeIdInTemplateTest.expect index 580632fe..c0b13eb5 100644 --- a/tests/TypeIdInTemplateTest.expect +++ b/tests/TypeIdInTemplateTest.expect @@ -10,7 +10,7 @@ class Foo public: inline std::basic_string, std::allocator > Get() { - std::basic_string, std::allocator > typeId = std::basic_string, std::allocator >{typeid(const std::type_info).name()} /* NRVO variable */; + std::basic_string, std::allocator > typeId = std::basic_string, std::allocator >{typeid(T).name()} /* NRVO variable */; return std::basic_string, std::allocator >(static_cast, std::allocator > &&>(typeId)); } @@ -25,7 +25,7 @@ class Foo public: inline std::basic_string, std::allocator > Get() { - std::basic_string, std::allocator > typeId = std::basic_string, std::allocator >{typeid(const std::type_info).name()} /* NRVO variable */; + std::basic_string, std::allocator > typeId = std::basic_string, std::allocator >{typeid(int).name()} /* NRVO variable */; return std::basic_string, std::allocator >(static_cast, std::allocator > &&>(typeId)); }