Skip to content

Commit

Permalink
Merge pull request #523 from andreasfertig/fixIssue522
Browse files Browse the repository at this point in the history
Fixed #522: Keep the type of the `typeid` expression as written.
  • Loading branch information
andreasfertig authored Apr 12, 2023
2 parents 5b64999 + 8af7b1a commit 69df61d
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 69df61d

Please sign in to comment.