-
Notifications
You must be signed in to change notification settings - Fork 11.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[clang-tidy] Generates invalid code - adds invalid escapes to string literals #56669
Comments
I used VSCode's plugin to fix the clang-tidy issues automatically: https://github.com/microsoft/vscode-cpptools |
Could you please run tools separately to find which one causes problem? |
It's clang-tidy. Please check the the screenshot - Line 45. It's an unformatted output. I think VSCode includes clang-tidy 14. I'm running the VSCode on Ubuntu 22.04/INTEL. |
At the top I copy and pasted the before and after fixes. Please note:
// fprintf(stderr, "CheckModified() Reloading Configuration [%s]\n", Buf); -> // fprintf(stderr, \"CheckModified() Reloading Configuration [%s]\
\", Buf); |
@llvm/issue-subscribers-clang-tidy |
It would be also nice when removing: } else {
return x;
} To put the |
---
AnalyzeTemporaryDtors: false
FormatStyle: none
HeaderFilterRegex: 'agent/[^/]*\.(hpp|cpp|hxx|cxx)$|library/[^/]*\.(hpp|cpp|hxx|cxx)$|initial-validate/[^/]*\.(hpp|cpp|hxx|cxx)$|modules/[^/]*\.(hpp|cpp|hxx|cxx)$'
User: user
WarningsAsErrors: false
# Checks order:
# 1. Disable all default checks `-*`
# 2. Enable all desired checks `-<check_name_group>-*`
# 3. Disable specific checks with `-<check_name>`
Checks: >
-*,
boost-*,
bugprone-*,
cert-*,
clang-analyzer-*,
clang-diagnostic-*,
concurrency-*,
cppcoreguidelines-*,
google-*,
hicpp-*,
misc-*,
modernize-*,
performance-*,
portability-*,
readability-*,
-modernize-use-trailing-return-type,
-readability-redundant-access-specifiers,
CheckOptions:
- key: cert-dcl16-c.NewSuffixes
value: 'L;LL;LU;LLU'
- key: cert-oop54-cpp.WarnOnlyIfThisHasSuspiciousField
value: 'false'
- key: cert-str34-c.DiagnoseSignedUnsignedCharComparisons
value: 'false'
- key: google-readability-namespace-comments.ShortNamespaceLines
value: '10'
- key: cppcoreguidelines-explicit-virtual-functions.IgnoreDestructors
value: 'true'
- key: cppcoreguidelines-special-member-functions.AllowSoleDefaultDtor
value: 'true'
- key: cppcoreguidelines-non-private-member-variables-in-classes.IgnoreClassesWithAllMemberVariablesBeingPublic
value: 'true'
- key: google-readability-braces-around-statements.ShortStatementLines
value: '1'
- key: google-readability-function-size.StatementThreshold
value: '800'
- key: google-readability-namespace-comments.SpacesBeforeComments
value: '2'
- key: llvm-else-after-return.WarnOnConditionVariables
value: 'false'
- key: llvm-else-after-return.WarnOnUnfixable
value: 'false'
- key: llvm-qualified-auto.AddConstToQualified
value: 'false'
- key: misc-non-private-member-variables-in-classes.IgnoreClassesWithAllMemberVariablesBeingPublic
value: 'true'
- key: modernize-loop-convert.MaxCopySize
value: '16'
- key: modernize-loop-convert.MinConfidence
value: reasonable
- key: modernize-loop-convert.NamingStyle
value: CamelCase
- key: modernize-pass-by-value.IncludeStyle
value: llvm
- key: modernize-replace-auto-ptr.IncludeStyle
value: llvm
- key: modernize-use-nullptr.NullMacros
value: 'NULL'
... Applying the above on: #define MAX_FILENAME 2
char* szConfigName;
void ResetState() {}
void LoadConfig(char** buf) {(void) buf; }
void CheckModified() {
struct stat fileinfo;
time_t mytime;
char Buf[MAX_FILENAME];
if (stat(szConfigName, &fileinfo) == -1) {
fprintf(stderr, "CheckModified() Error: Cannot stat [%s]!\n", szConfigName);
return;
} else {
mytime = fileinfo.st_mtime;
if (mytime > 1) {
snprintf(Buf, MAX_FILENAME, "%s", szConfigName);
// BugID 7073: Suppressing output to stderr, it seems to be bothering dave.
// fprintf(stderr, "CheckModified() Reloading Configuration [%s]\n", Buf);
ResetState();
LoadConfig(Buf);
}
}
} produces: #define MAX_FILENAME 2
char* szConfigName;
void ResetState() {}
void LoadConfig(char** buf) {(void) buf; }
void CheckModified() {
struct stat fileinfo;
time_t mytime = 0;
char Buf[MAX_FILENAME];
if (stat(szConfigName, &fileinfo) == -1) {
fprintf(stderr, "CheckModified() Error: Cannot stat [%s]!\n", szConfigName);
return;
} mytime = fileinfo.st_mtime;
if (mytime > 1) {
snprintf(Buf, MAX_FILENAME, \"%s\", szConfigName);
// BugID 7073: Suppressing output to stderr, it seems to be bothering dave.
// fprintf(stderr, \"CheckModified() Reloading Configuration [%s]\
\", Buf);
ResetState();
LoadConfig(Buf);
}
} |
What's the warning that clang tidy is emitting for that fix? |
I'm just selecting a Fix all code analysis problems from the menu. This a minimal CMake project that reproduces this on my machine: I'll post the same here microsoft/vscode-cpptools#9683 In case it is a VSCode issue. |
More specific - now I selected to fix: readability-else-after-return. |
@njames93 I installed clang-tidy locally and run: |
Yeah, there was a bug with our processing of the clang-tidy fixes.yaml output -- so I think this issue can be closed. |
The following was automatically fixed by Clang-Tidy and reformatted with clang-format:
Invalid output:
The text was updated successfully, but these errors were encountered: