Skip to content

Commit

Permalink
Fixed #522: Keep the type of the typeid expression as written.
Browse files Browse the repository at this point in the history
  • Loading branch information
andreasfertig committed Apr 12, 2023
1 parent 5b64999 commit 8af7b1a
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 3 deletions.
2 changes: 1 addition & 1 deletion CodeGenerator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<ASTContext&>(GetGlobalAST()))));
} else {
InsertArg(stmt->getExprOperand());
}
Expand Down
3 changes: 3 additions & 0 deletions tests/Issue522.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#include <typeinfo>
std::type_info const& tiA = typeid(int);
std::type_info const& tiB = typeid(0);
5 changes: 5 additions & 0 deletions tests/Issue522.expect
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#include <typeinfo>
const std::type_info & tiA = typeid(int);

const std::type_info & tiB = typeid(0);

4 changes: 2 additions & 2 deletions tests/TypeIdInTemplateTest.expect
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ class Foo
public:
inline std::basic_string<char, std::char_traits<char>, std::allocator<char> > Get()
{
std::basic_string<char, std::char_traits<char>, std::allocator<char> > typeId = std::basic_string<char, std::char_traits<char>, std::allocator<char> >{typeid(const std::type_info).name()} /* NRVO variable */;
std::basic_string<char, std::char_traits<char>, std::allocator<char> > typeId = std::basic_string<char, std::char_traits<char>, std::allocator<char> >{typeid(T).name()} /* NRVO variable */;
return std::basic_string<char, std::char_traits<char>, std::allocator<char> >(static_cast<std::basic_string<char, std::char_traits<char>, std::allocator<char> > &&>(typeId));
}

Expand All @@ -25,7 +25,7 @@ class Foo<int>
public:
inline std::basic_string<char, std::char_traits<char>, std::allocator<char> > Get()
{
std::basic_string<char, std::char_traits<char>, std::allocator<char> > typeId = std::basic_string<char, std::char_traits<char>, std::allocator<char> >{typeid(const std::type_info).name()} /* NRVO variable */;
std::basic_string<char, std::char_traits<char>, std::allocator<char> > typeId = std::basic_string<char, std::char_traits<char>, std::allocator<char> >{typeid(int).name()} /* NRVO variable */;
return std::basic_string<char, std::char_traits<char>, std::allocator<char> >(static_cast<std::basic_string<char, std::char_traits<char>, std::allocator<char> > &&>(typeId));
}

Expand Down

0 comments on commit 8af7b1a

Please sign in to comment.