Skip to content

Commit 16686c1

Browse files
committed
Give better diagnostic for invalid/ambiguous compiler flag
1 parent 71b9cb0 commit 16686c1

File tree

4 files changed

+32
-2
lines changed

4 files changed

+32
-2
lines changed

regression-tests/test-results/version

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11

2-
cppfront compiler v0.7.1 Build 9717:1027
2+
cppfront compiler v0.7.1 Build 9718:1445
33
Copyright(c) Herb Sutter All rights reserved
44

55
SPDX-License-Identifier: CC-BY-NC-ND-4.0

source/build.info

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
"9717:1027"
1+
"9718:1445"

source/common.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -669,6 +669,18 @@ class cmdline_processor
669669
}
670670

671671
public:
672+
auto flags_starting_with(std::string_view s)
673+
-> std::vector<std::string>
674+
{
675+
auto ret = std::vector<std::string>{};
676+
for (auto const& f : flags) {
677+
if (f.name.starts_with(s)) {
678+
ret.push_back(f.name);
679+
}
680+
}
681+
return ret;
682+
}
683+
672684
auto process_flags()
673685
-> void
674686
{

source/cppfront.cpp

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,24 @@ auto main(
6161
int exit_status = EXIT_SUCCESS;
6262
for (auto const& arg : cmdline.arguments())
6363
{
64+
if (
65+
arg.text.starts_with("-")
66+
|| arg.text.starts_with("/")
67+
)
68+
{
69+
auto ambiguous = cmdline.flags_starting_with(arg.text.substr(1));
70+
if (ambiguous.empty()) {
71+
std::cerr << arg.text << " - unknown compiler flag name (try " << arg.text.front() << "help)\n";
72+
}
73+
else {
74+
std::cerr << arg.text << " - ambiguous compiler flag name, did you mean one of these?\n";
75+
for (auto a : ambiguous) {
76+
std::cerr << " " << arg.text.front() << a << "\n";
77+
}
78+
}
79+
return EXIT_FAILURE;
80+
}
81+
6482
cpp2::timer t;
6583
t.start();
6684

0 commit comments

Comments
 (0)