Skip to content

Commit

Permalink
Fixed #598: Added basic support for SourceLocExpr.
Browse files Browse the repository at this point in the history
Basic means that the expression is not evaluated. C++ Insights only
echos the builtin name that was used.
  • Loading branch information
andreasfertig committed Jan 9, 2024
1 parent baa5b4a commit 0f8d46a
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 0 deletions.
6 changes: 6 additions & 0 deletions CodeGenerator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -589,6 +589,12 @@ static std::optional<std::string> GetFieldDeclNameForLambda(const FieldDecl&
}
//-----------------------------------------------------------------------------

void CodeGenerator::InsertArg(const SourceLocExpr* stmt)
{
mOutputFormatHelper.Append(stmt->getBuiltinStr(), "()"sv);
}
//-----------------------------------------------------------------------------

void CodeGenerator::InsertArg(const MemberExpr* stmt)
{
const auto* base = stmt->getBase();
Expand Down
1 change: 1 addition & 0 deletions CodeGeneratorTypes.h
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@ SUPPORTED_STMT(AttributedStmt)
SUPPORTED_STMT(ConceptSpecializationExpr)
SUPPORTED_STMT(RequiresExpr)
SUPPORTED_STMT(StmtExpr)
SUPPORTED_STMT(SourceLocExpr)
SUPPORTED_STMT(CppInsightsCommentStmt)

#undef IGNORED_DECL
Expand Down
7 changes: 7 additions & 0 deletions tests/Issue598.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
// cmdline:-std=c++20

#include <source_location>

auto s = std::source_location::current();

auto X = __builtin_LINE();
9 changes: 9 additions & 0 deletions tests/Issue598.expect
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
// cmdline:-std=c++20

#include <source_location>

std::source_location s = std::source_location::current(__builtin_source_location());


unsigned int X = __builtin_LINE();

0 comments on commit 0f8d46a

Please sign in to comment.