Skip to content

Commit 0a1fbe7

Browse files
committed
[Macros] Emit deprecation warnings for uses of freestanding macros.
Fixes rdar://113138432.
1 parent aa397c7 commit 0a1fbe7

File tree

2 files changed

+25
-0
lines changed

2 files changed

+25
-0
lines changed

lib/Sema/TypeCheckAvailability.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3285,6 +3285,11 @@ class ExprAvailabilityWalker : public ASTWalker {
32853285
}
32863286
}
32873287

3288+
if (auto ME = dyn_cast<MacroExpansionExpr>(E)) {
3289+
diagnoseDeclRefAvailability(
3290+
ME->getMacroRef(), ME->getMacroNameLoc().getSourceRange());
3291+
}
3292+
32883293
return Action::Continue(E);
32893294
}
32903295

test/Macros/macro_expand.swift

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -547,3 +547,23 @@ func testExpressionAsDeclarationMacro() {
547547
// expected-error@-1{{macro implementation type 'StringifyMacro' doesn't conform to required protocol 'DeclarationMacro' (from macro 'stringifyAsDeclMacro')}}
548548
#endif
549549
}
550+
551+
// Deprecated macro
552+
@available(*, deprecated, message: "This macro is deprecated.")
553+
@freestanding(expression) macro deprecatedStringify<T>(_ value: T) -> (T, String) = #externalMacro(module: "MacroDefinition", type: "StringifyMacro")
554+
555+
@available(*, deprecated, message: "This macro is deprecated.")
556+
@freestanding(declaration) macro deprecatedStringifyAsDeclMacro<T>(_ value: T) = #externalMacro(module: "MacroDefinition", type: "StringifyMacro")
557+
558+
func testDeprecated() {
559+
// expected-warning@+1{{'deprecatedStringify' is deprecated: This macro is deprecated.}}
560+
_ = #deprecatedStringify(1 + 1)
561+
}
562+
563+
#if TEST_DIAGNOSTICS
564+
struct DeprecatedStructWrapper {
565+
// expected-error@+2{{macro implementation type 'StringifyMacro' doesn't conform to required protocol 'DeclarationMacro' (from macro 'deprecatedStringifyAsDeclMacro')}}
566+
// expected-warning@+1{{'deprecatedStringifyAsDeclMacro' is deprecated: This macro is deprecated.}}
567+
#deprecatedStringifyAsDeclMacro(1 + 1)
568+
}
569+
#endif

0 commit comments

Comments
 (0)