Skip to content

[clang-tidy] verify-config option gives false negatives #162506

@0hDEADBEAF

Description

@0hDEADBEAF

Description: Some invalid check options from readability-identifier-naming check are not triggering warnings from --verify-config command-line option with clang-tidy. It seems that every type from readability-identifier-naming check that does not have a HungarianPrefix option gives this error.

There may have other options from other checks causing this error, I can't really test them all.

From what I've seen, here's the list of the invalid check options that are not being detected as such when invoking the --verify-config clang-tidy command-line option.

  • NamespaceHungarianPrefix
  • InlineNamespaceHungarianPrefix
  • ParameterPackHungarianPrefix
  • GlobalFunctionHungarianPrefix
  • ConstexprFunctionHungarianPrefix
  • FunctionHungarianPrefix
  • ConstexprMethodHungarianPrefix
  • VirtualMethodHungarianPrefix
  • ClassMethodHungarianPrefix
  • PrivateMethodHungarianPrefix
  • ProtectedMethodHungarianPrefix
  • PublicMethodHungarianPrefix
  • MethodHungarianPrefix
  • TypedefHungarianPrefix
  • TypeTemplateParameterHungarianPrefix
  • ValueTemplateParameterHungarianPrefix
  • TemplateTemplateParameterHungarianPrefix
  • TemplateParameterHungarianPrefix
  • TypeAliasHungarianPrefix
  • MacroDefinitionHungarianPrefix
  • ObjcIvarHungarianPrefix
  • ConceptHungarianPrefix

Branch: main

Steps to reproduce:

clang-tidy --verify-config --config="{ Checks: 'readability-identifier-naming', CheckOptions: { readability-identifier-naming.ConceptHungarianPrefix: 'Off' } }" # That will not trigger a warning as it should
clang-tidy --config="{ Checks: 'readability-identifier-naming', CheckOptions: { readability-identifier-naming.ConceptHungarianPrefix: 'Off' } }" test.cpp # This will trigger a warning, telling us that readability-identifier-naming.ConceptHungarianPrefix is not a valid option

With test.cpp being a placeholder C++ file, it doesn't matter what it contains.

Of course, ConceptHungarianPrefix can be replaced by any option listed above.

I've made a small Python script that prints the invalid options that are not detected as such (that's how I got the list):

import subprocess

clang_tidy_path = <PATH_TO_CLANG_TIDY>
options = ["Namespace", "InlineNamespace", "EnumConstant", "ScopedEnumConstant", "ConstexprVariable", "ConstantMember", "PrivateMember", "ProtectedMember", "PublicMember", "Member", "ClassConstant", "ClassMember", "GlobalConstant", "GlobalConstantPointer", "GlobalPointer", "GlobalVariable", "LocalConstant", "LocalConstantPointer", "LocalPointer", "LocalVariable", "StaticConstant", "StaticVariable", "Constant", "Variable", "ConstantParameter", "ParameterPack", "Parameter", "PointerParameter", "ConstantPointerParameter", "AbstractClass", "Struct", "Class", "Union", "Enum", "GlobalFunction", "ConstexprFunction", "Function", "ConstexprMethod", "VirtualMethod", "ClassMethod", "PrivateMethod", "ProtectedMethod", "PublicMethod", "Method", "Typedef", "TypeTemplateParameter", "ValueTemplateParameter", "TemplateTemplateParameter", "TemplateParameter", "TypeAlias", "MacroDefinition", "ObjcIvar", "Concept"]

for option in options:
    config = "{ Checks: 'readability-identifier-naming', CheckOptions: { readability-identifier-naming." + option + "HungarianPrefix: 'Off' } }"
    verify_result = subprocess.run([clang_tidy_path, "--verify-config", f"--config={config}"], capture_output=True)
    run_result = subprocess.run([clang_tidy_path, f"--config={config}", "./test.cpp"], capture_output=True)
    verify_ok = verify_result.stdout == b'No config errors detected.\n'
    run_ok = run_result.stdout != b"warning: invalid identifier naming option '" + option.encode("utf-8") + b"HungarianPrefix' [clang-tidy-config]\n"
    if verify_ok != run_ok:
        print(option)

Expected result: The two commands should be coherent and give a warning.

Actual result: --verify-config does not warn about some invalid check options.

Additional notes: I'm not yet familiar with clang-tidy source code but if you think this is fine for me to try to fix this issue, I would be glad to try to. I would like to become familiar with clang-tidy source code and I feel like this would be a good start to. What do you think?

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions