Skip to content

Commit be4c2b9

Browse files
authored
Merge pull request swiftlang#14950 from Nonchalant/sr_7040_redundant_D
[SR-7040] Redundant prefix of compilation flag specific error
2 parents 5eb6864 + daef1cb commit be4c2b9

File tree

3 files changed

+8
-1
lines changed

3 files changed

+8
-1
lines changed

include/swift/AST/DiagnosticsFrontend.def

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,10 @@ ERROR(symbol_in_ir_not_in_tbd,none,
209209
"symbol '%0' (%1) is in generated IR file, but not in TBD file",
210210
(StringRef, StringRef))
211211

212+
ERROR(redundant_prefix_compilation_flag,none,
213+
"invalid argument '-D%0'; did you provide a redundant '-D' in your build settings?",
214+
(StringRef))
215+
212216
ERROR(invalid_conditional_compilation_flag,none,
213217
"conditional compilation flags must be valid Swift identifiers (rather than '%0')",
214218
(StringRef))

lib/Driver/Driver.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,9 @@ static void validateArgs(DiagnosticEngine &diags, const ArgList &Args) {
192192
diags.diagnose(SourceLoc(),
193193
diag::cannot_assign_value_to_conditional_compilation_flag,
194194
name);
195+
else if (name.startswith("-D"))
196+
diags.diagnose(SourceLoc(), diag::redundant_prefix_compilation_flag,
197+
name);
195198
else if (!Lexer::isIdentifier(name))
196199
diags.diagnose(SourceLoc(), diag::invalid_conditional_compilation_flag,
197200
name);

test/Frontend/unknown-arguments.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,5 @@
1010
// RUN: not %swiftc_driver -D Correct -DAlsoCorrect -D@#%! -D Swift=Cool -D-D -c %s -o %t.o 2>&1 | %FileCheck -check-prefix=INVALID-COND %s
1111
// INVALID-COND: <unknown>:0: error: conditional compilation flags must be valid Swift identifiers (rather than '@#%!')
1212
// INVALID-COND-NEXT: <unknown>:0: warning: conditional compilation flags do not have values in Swift; they are either present or absent (rather than 'Swift=Cool')
13-
// INVALID-COND-NEXT: <unknown>:0: error: conditional compilation flags must be valid Swift identifiers (rather than '-D')
13+
// INVALID-COND-NEXT: <unknown>:0: error: invalid argument '-D-D'; did you provide a redundant '-D' in your build settings?
1414

0 commit comments

Comments
 (0)