llvm-project/clang/test/TableGen/deferred-diag.td
Aaron Ballman 24a12a9c85
[clang] Diagnose problematic diagnostic messages (#93229)
Clang has some unwritten rules about diagnostic wording regarding things
like punctuation and capitalization. This patch documents those rules
and adds some tablegen support for checking diagnostics follow the
rules.

Specifically: tablegen now checks that a diagnostic does not start with
a capital letter or end with punctuation, except for the usual
exceptions like proper nouns or ending with a question.

Now that the code base is clean of such issues, the diagnostics are
emitted as an error rather than a warning to ensure that failure to
follow these rules is either addressed by an author, or a new exception
is added to the checking logic.
2024-05-28 09:22:55 -04:00

28 lines
1.2 KiB
TableGen

// RUN: clang-tblgen -gen-clang-diags-defs -I%S %s -o - 2>&1 | \
// RUN: FileCheck --strict-whitespace %s
include "DiagnosticBase.inc"
// Test usage of Deferrable and NonDeferrable in diagnostics.
def test_default : Error<"this error is non-deferrable by default">;
// CHECK-DAG: DIAG(test_default, {{.*}}SFINAE_SubstitutionFailure, false, true, true, false, 0)
def test_deferrable : Error<"this error is deferrable">, Deferrable;
// CHECK-DAG: DIAG(test_deferrable, {{.*}} SFINAE_SubstitutionFailure, false, true, true, true, 0)
def test_non_deferrable : Error<"this error is non-deferrable">, NonDeferrable;
// CHECK-DAG: DIAG(test_non_deferrable, {{.*}} SFINAE_SubstitutionFailure, false, true, true, false, 0)
let Deferrable = 1 in {
def test_let : Error<"this error is deferrable by let">;
// CHECK-DAG: DIAG(test_let, {{.*}} SFINAE_SubstitutionFailure, false, true, true, true, 0)
// Make sure TextSubstitution is allowed in the let Deferrable block.
def textsub : TextSubstitution<"%select{text1|text2}0">;
def test_let2 : Error<"this error is deferrable by let %sub{textsub}0">;
// CHECK-DAG: DIAG(test_let2, {{.*}} SFINAE_SubstitutionFailure, false, true, true, true, 0)
}