Search code examples
c++clang-tidy

clang-tidy default checks (unknown origin)


My clang-tidy seems to have some hardcoded options I cannot get rid of, without any .clang-file (as seen in --explain-config below):

clang-tidy --checks=-* --dump-config
---
Checks:          'clang-diagnostic-*,clang-analyzer-*,-*'
WarningsAsErrors: ''
HeaderFilterRegex: ''
AnalyzeTemporaryDtors: false
FormatStyle:     none
User:            <my user>
CheckOptions:
  llvm-else-after-return.WarnOnConditionVariables: 'false'
  modernize-loop-convert.MinConfidence: reasonable
  modernize-replace-auto-ptr.IncludeStyle: llvm
  cert-str34-c.DiagnoseSignedUnsignedCharComparisons: 'false'
  google-readability-namespace-comments.ShortNamespaceLines: '10'
  cert-err33-c.CheckedFunctions: '::aligned_alloc;::asctime_s;::at_quick_exit;::atexit;::bsearch;::bsearch_s;::btowc;::c16rtomb;::c32rtomb;::calloc;::clock;::cnd_broadcast;::cnd_init;::cnd_signal;::cnd_timedwait;::cnd_wait;::ctime_s;::fclose;::fflush;::fgetc;::fgetpos;::fgets;::fgetwc;::fopen;::fopen_s;::fprintf;::fprintf_s;::fputc;::fputs;::fputwc;::fputws;::fread;::freopen;::freopen_s;::fscanf;::fscanf_s;::fseek;::fsetpos;::ftell;::fwprintf;::fwprintf_s;::fwrite;::fwscanf;::fwscanf_s;::getc;::getchar;::getenv;::getenv_s;::gets_s;::getwc;::getwchar;::gmtime;::gmtime_s;::localtime;::localtime_s;::malloc;::mbrtoc16;::mbrtoc32;::mbsrtowcs;::mbsrtowcs_s;::mbstowcs;::mbstowcs_s;::memchr;::mktime;::mtx_init;::mtx_lock;::mtx_timedlock;::mtx_trylock;::mtx_unlock;::printf_s;::putc;::putwc;::raise;::realloc;::remove;::rename;::scanf;::scanf_s;::setlocale;::setvbuf;::signal;::snprintf;::snprintf_s;::sprintf;::sprintf_s;::sscanf;::sscanf_s;::strchr;::strerror_s;::strftime;::strpbrk;::strrchr;::strstr;::strtod;::strtof;::strtoimax;::strtok;::strtok_s;::strtol;::strtold;::strtoll;::strtoul;::strtoull;::strtoumax;::strxfrm;::swprintf;::swprintf_s;::swscanf;::swscanf_s;::thrd_create;::thrd_detach;::thrd_join;::thrd_sleep;::time;::timespec_get;::tmpfile;::tmpfile_s;::tmpnam;::tmpnam_s;::tss_create;::tss_get;::tss_set;::ungetc;::ungetwc;::vfprintf;::vfprintf_s;::vfscanf;::vfscanf_s;::vfwprintf;::vfwprintf_s;::vfwscanf;::vfwscanf_s;::vprintf_s;::vscanf;::vscanf_s;::vsnprintf;::vsnprintf_s;::vsprintf;::vsprintf_s;::vsscanf;::vsscanf_s;::vswprintf;::vswprintf_s;::vswscanf;::vswscanf_s;::vwprintf_s;::vwscanf;::vwscanf_s;::wcrtomb;::wcschr;::wcsftime;::wcspbrk;::wcsrchr;::wcsrtombs;::wcsrtombs_s;::wcsstr;::wcstod;::wcstof;::wcstoimax;::wcstok;::wcstok_s;::wcstol;::wcstold;::wcstoll;::wcstombs;::wcstombs_s;::wcstoul;::wcstoull;::wcstoumax;::wcsxfrm;::wctob;::wctrans;::wctype;::wmemchr;::wprintf_s;::wscanf;::wscanf_s;'
  cert-oop54-cpp.WarnOnlyIfThisHasSuspiciousField: 'false'
  cert-dcl16-c.NewSuffixes: 'L;LL;LU;LLU'
  google-readability-braces-around-statements.ShortStatementLines: '1'
  cppcoreguidelines-non-private-member-variables-in-classes.IgnoreClassesWithAllMemberVariablesBeingPublic: 'true'
  google-readability-namespace-comments.SpacesBeforeComments: '2'
  modernize-loop-convert.MaxCopySize: '16'
  modernize-pass-by-value.IncludeStyle: llvm
  modernize-use-nullptr.NullMacros: 'NULL'
  llvm-qualified-auto.AddConstToQualified: 'false'
  modernize-loop-convert.NamingStyle: CamelCase
  llvm-else-after-return.WarnOnUnfixable: 'false'
  google-readability-function-size.StatementThreshold: '800'
...

Where are those coming of and how can I get rid of them ? I discovered this by trying hard to overwrite readability-braces-around-statements.ShortNamespaceLines, but the default google-readability-braces-around-statements always win, unmovable.

No explanation when asked explicitly:

clang-tidy --dump-config --explain-config
'clang-analyzer-apiModeling.Errno' is enabled in the clang-tidy binary.
'clang-analyzer-apiModeling.StdCLibraryFunctions' is enabled in the clang-tidy binary.
'clang-analyzer-apiModeling.TrustNonnull' is enabled in the clang-tidy binary.
'clang-analyzer-apiModeling.TrustReturnsNonnull' is enabled in the clang-tidy binary.
'clang-analyzer-apiModeling.google.GTest' is enabled in the clang-tidy binary.
'clang-analyzer-apiModeling.llvm.CastValue' is enabled in the clang-tidy binary.
'clang-analyzer-apiModeling.llvm.ReturnValue' is enabled in the clang-tidy binary.
'clang-analyzer-core.CallAndMessage' is enabled in the clang-tidy binary.
'clang-analyzer-core.CallAndMessageModeling' is enabled in the clang-tidy binary.
'clang-analyzer-core.DivideZero' is enabled in the clang-tidy binary.
'clang-analyzer-core.DynamicTypePropagation' is enabled in the clang-tidy binary.
'clang-analyzer-core.NonNullParamChecker' is enabled in the clang-tidy binary.
'clang-analyzer-core.NonnilStringConstants' is enabled in the clang-tidy binary.
'clang-analyzer-core.NullDereference' is enabled in the clang-tidy binary.
'clang-analyzer-core.StackAddrEscapeBase' is enabled in the clang-tidy binary.
'clang-analyzer-core.StackAddressEscape' is enabled in the clang-tidy binary.
'clang-analyzer-core.UndefinedBinaryOperatorResult' is enabled in the clang-tidy binary.
'clang-analyzer-core.VLASize' is enabled in the clang-tidy binary.
'clang-analyzer-core.builtin.BuiltinFunctions' is enabled in the clang-tidy binary.
'clang-analyzer-core.builtin.NoReturnFunctions' is enabled in the clang-tidy binary.
'clang-analyzer-core.uninitialized.ArraySubscript' is enabled in the clang-tidy binary.
'clang-analyzer-core.uninitialized.Assign' is enabled in the clang-tidy binary.
'clang-analyzer-core.uninitialized.Branch' is enabled in the clang-tidy binary.
'clang-analyzer-core.uninitialized.CapturedBlockVariable' is enabled in the clang-tidy binary.
'clang-analyzer-core.uninitialized.UndefReturn' is enabled in the clang-tidy binary.
'clang-analyzer-cplusplus.InnerPointer' is enabled in the clang-tidy binary.
'clang-analyzer-cplusplus.Move' is enabled in the clang-tidy binary.
'clang-analyzer-cplusplus.NewDelete' is enabled in the clang-tidy binary.
'clang-analyzer-cplusplus.NewDeleteLeaks' is enabled in the clang-tidy binary.
'clang-analyzer-cplusplus.PlacementNew' is enabled in the clang-tidy binary.
'clang-analyzer-cplusplus.PureVirtualCall' is enabled in the clang-tidy binary.
'clang-analyzer-cplusplus.SelfAssignment' is enabled in the clang-tidy binary.
'clang-analyzer-cplusplus.SmartPtrModeling' is enabled in the clang-tidy binary.
'clang-analyzer-cplusplus.StringChecker' is enabled in the clang-tidy binary.
'clang-analyzer-cplusplus.VirtualCallModeling' is enabled in the clang-tidy binary.
'clang-analyzer-deadcode.DeadStores' is enabled in the clang-tidy binary.
'clang-analyzer-fuchsia.HandleChecker' is enabled in the clang-tidy binary.
'clang-analyzer-nullability.NullPassedToNonnull' is enabled in the clang-tidy binary.
'clang-analyzer-nullability.NullReturnedFromNonnull' is enabled in the clang-tidy binary.
'clang-analyzer-nullability.NullabilityBase' is enabled in the clang-tidy binary.
'clang-analyzer-nullability.NullableDereferenced' is enabled in the clang-tidy binary.
'clang-analyzer-nullability.NullablePassedToNonnull' is enabled in the clang-tidy binary.
'clang-analyzer-nullability.NullableReturnedFromNonnull' is enabled in the clang-tidy binary.
'clang-analyzer-optin.cplusplus.UninitializedObject' is enabled in the clang-tidy binary.
'clang-analyzer-optin.cplusplus.VirtualCall' is enabled in the clang-tidy binary.
'clang-analyzer-optin.mpi.MPI-Checker' is enabled in the clang-tidy binary.
'clang-analyzer-optin.osx.OSObjectCStyleCast' is enabled in the clang-tidy binary.
'clang-analyzer-optin.osx.cocoa.localizability.EmptyLocalizationContextChecker' is enabled in the clang-tidy binary.
'clang-analyzer-optin.osx.cocoa.localizability.NonLocalizedStringChecker' is enabled in the clang-tidy binary.
'clang-analyzer-optin.performance.GCDAntipattern' is enabled in the clang-tidy binary.
'clang-analyzer-optin.performance.Padding' is enabled in the clang-tidy binary.
'clang-analyzer-optin.portability.UnixAPI' is enabled in the clang-tidy binary.
'clang-analyzer-osx.API' is enabled in the clang-tidy binary.
'clang-analyzer-osx.MIG' is enabled in the clang-tidy binary.
'clang-analyzer-osx.NSOrCFErrorDerefChecker' is enabled in the clang-tidy binary.
'clang-analyzer-osx.NumberObjectConversion' is enabled in the clang-tidy binary.
'clang-analyzer-osx.OSObjectRetainCount' is enabled in the clang-tidy binary.
'clang-analyzer-osx.ObjCProperty' is enabled in the clang-tidy binary.
'clang-analyzer-osx.SecKeychainAPI' is enabled in the clang-tidy binary.
'clang-analyzer-osx.cocoa.AtSync' is enabled in the clang-tidy binary.
'clang-analyzer-osx.cocoa.AutoreleaseWrite' is enabled in the clang-tidy binary.
'clang-analyzer-osx.cocoa.ClassRelease' is enabled in the clang-tidy binary.
'clang-analyzer-osx.cocoa.Dealloc' is enabled in the clang-tidy binary.
'clang-analyzer-osx.cocoa.IncompatibleMethodTypes' is enabled in the clang-tidy binary.
'clang-analyzer-osx.cocoa.Loops' is enabled in the clang-tidy binary.
'clang-analyzer-osx.cocoa.MissingSuperCall' is enabled in the clang-tidy binary.
'clang-analyzer-osx.cocoa.NSAutoreleasePool' is enabled in the clang-tidy binary.
'clang-analyzer-osx.cocoa.NSError' is enabled in the clang-tidy binary.
'clang-analyzer-osx.cocoa.NilArg' is enabled in the clang-tidy binary.
'clang-analyzer-osx.cocoa.NonNilReturnValue' is enabled in the clang-tidy binary.
'clang-analyzer-osx.cocoa.ObjCGenerics' is enabled in the clang-tidy binary.
'clang-analyzer-osx.cocoa.RetainCount' is enabled in the clang-tidy binary.
'clang-analyzer-osx.cocoa.RetainCountBase' is enabled in the clang-tidy binary.
'clang-analyzer-osx.cocoa.RunLoopAutoreleaseLeak' is enabled in the clang-tidy binary.
'clang-analyzer-osx.cocoa.SelfInit' is enabled in the clang-tidy binary.
'clang-analyzer-osx.cocoa.SuperDealloc' is enabled in the clang-tidy binary.
'clang-analyzer-osx.cocoa.UnusedIvars' is enabled in the clang-tidy binary.
'clang-analyzer-osx.cocoa.VariadicMethodTypes' is enabled in the clang-tidy binary.
'clang-analyzer-osx.coreFoundation.CFError' is enabled in the clang-tidy binary.
'clang-analyzer-osx.coreFoundation.CFNumber' is enabled in the clang-tidy binary.
'clang-analyzer-osx.coreFoundation.CFRetainRelease' is enabled in the clang-tidy binary.
'clang-analyzer-osx.coreFoundation.containers.OutOfBounds' is enabled in the clang-tidy binary.
'clang-analyzer-osx.coreFoundation.containers.PointerSizedValues' is enabled in the clang-tidy binary.
'clang-analyzer-security.FloatLoopCounter' is enabled in the clang-tidy binary.
'clang-analyzer-security.insecureAPI.DeprecatedOrUnsafeBufferHandling' is enabled in the clang-tidy binary.
'clang-analyzer-security.insecureAPI.SecuritySyntaxChecker' is enabled in the clang-tidy binary.
'clang-analyzer-security.insecureAPI.UncheckedReturn' is enabled in the clang-tidy binary.
'clang-analyzer-security.insecureAPI.bcmp' is enabled in the clang-tidy binary.
'clang-analyzer-security.insecureAPI.bcopy' is enabled in the clang-tidy binary.
'clang-analyzer-security.insecureAPI.bzero' is enabled in the clang-tidy binary.
'clang-analyzer-security.insecureAPI.decodeValueOfObjCType' is enabled in the clang-tidy binary.
'clang-analyzer-security.insecureAPI.getpw' is enabled in the clang-tidy binary.
'clang-analyzer-security.insecureAPI.gets' is enabled in the clang-tidy binary.
'clang-analyzer-security.insecureAPI.mkstemp' is enabled in the clang-tidy binary.
'clang-analyzer-security.insecureAPI.mktemp' is enabled in the clang-tidy binary.
'clang-analyzer-security.insecureAPI.rand' is enabled in the clang-tidy binary.
'clang-analyzer-security.insecureAPI.strcpy' is enabled in the clang-tidy binary.
'clang-analyzer-security.insecureAPI.vfork' is enabled in the clang-tidy binary.
'clang-analyzer-unix.API' is enabled in the clang-tidy binary.
'clang-analyzer-unix.DynamicMemoryModeling' is enabled in the clang-tidy binary.
'clang-analyzer-unix.Malloc' is enabled in the clang-tidy binary.
'clang-analyzer-unix.MallocSizeof' is enabled in the clang-tidy binary.
'clang-analyzer-unix.MismatchedDeallocator' is enabled in the clang-tidy binary.
'clang-analyzer-unix.Vfork' is enabled in the clang-tidy binary.
'clang-analyzer-unix.cstring.BadSizeArg' is enabled in the clang-tidy binary.
'clang-analyzer-unix.cstring.CStringModeling' is enabled in the clang-tidy binary.
'clang-analyzer-unix.cstring.NullArg' is enabled in the clang-tidy binary.
'clang-analyzer-valist.CopyToSelf' is enabled in the clang-tidy binary.
'clang-analyzer-valist.Uninitialized' is enabled in the clang-tidy binary.
'clang-analyzer-valist.Unterminated' is enabled in the clang-tidy binary.
'clang-analyzer-valist.ValistBase' is enabled in the clang-tidy binary.
'clang-analyzer-webkit.NoUncountedMemberChecker' is enabled in the clang-tidy binary.
'clang-analyzer-webkit.RefCntblBaseVirtualDtor' is enabled in the clang-tidy binary.
'clang-analyzer-webkit.UncountedLambdaCapturesChecker' is enabled in the clang-tidy binary.

Version:

clang-tidy --version
LLVM (http://llvm.org/):
  LLVM version 15.0.6
  Optimized build.
  Default target: x86_64-pc-windows-msvc
  Host CPU: tigerlake

Update

The above example does not involve any .clang-tidy file.

clang-tidy --fix-errors seems to work with the following .clang-tidy, even if google-readability-braces-around-statements.ShortStatementLines stays 1 in the dumped config.

Checks: hicpp-*, readability-identifier-naming,

CheckOptions:
  - { key: readability-identifier-naming.ClassCase, value: CamelCase}

# readability-braces-around-statements
# also see clang-format:InsertBraces
# aliases: hicpp-braces-around-statements, google-readability-braces-around-statements
# TODO: google-readability-braces-around-statements.ShortStatementLines is always there (--dump-config), 1, but won't be applied
  - { key: google-readability-braces-around-statements.ShortStatementLines, value: 3}
  - { key: hicpp-braces-around-statements.ShortStatementLines, value: 3}

Solution

  • When I run clang-tidy.exe --checks=-* --dump-config, I get the same output as you do:

    • The list of about 20 CheckOptions can be ignored, because these options are for checks that are disabled.
    • The only "checks" still apparently enabled are clang-diagnostic-*,clang-analyzer-*.

    These are "diagnostics" which -- unlike regular checks -- depend on corresponding clang compiler warnings being enabled as well. I.E. pass -- -Weverything at the end of your clang-tidy command line to enable all clang compiler warnings so that clang-diagnostic-*,clang-analyzer-* can notice them. Or you can enable only some clang warnings.

    Anyway, when I take away the --dump-config parameter and run clang-tidy.exe --checks=-* mysourcefile.cpp, I get Error: no checks enabled. So clang-tidy is honoring --checks=-*, but the help text generated by --dump-config appears to be incorrect.

    Running clang-tidy.exe --checks=-*,clang-diagnostic-*,clang-analyzer-* mysourcefile.cpp -- -Weverything produces the expected clang-diagnostic and clang-analyzer messages.

    Your .clang-tidy file that includes the line:

    Checks: hicpp-*, readability-identifier-naming,

    should probably be modified so the line looks like this:

    Checks: '-*,hicpp-*,readability-identifier-naming'

    In this way, you are explicitly disabling all the regular clang-tidy checks before explicitly enabling only the hicpp and readability-identifier-naming checks.