Skip to content
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

[C++] [clang-tidy] bugprone-reserved-identifier mistakenly changed JNI API to wrong one #121089

Open
forunix opened this issue Dec 25, 2024 · 0 comments

Comments

@forunix
Copy link

forunix commented Dec 25, 2024

Please help to fix the problem of bugprone-reserved-identifier in clang-tidy.

When the bugprone-reserved-identifier option of clang-tidy is enabled, it will change double underscores to one underscore. It will result in a runtime exception of 'java.lang.UnsatisfiedLinkError: No implementation found for xxx'.

As an example it will change Java_cn_xxx_xxx__I to Java_cn_xxx_xxx_I .

The build info is as follows.

C/C++: /Users/.../xxJNI.cpp:1740:24: warning: declaration uses identifier 'Java_cn_xxx_xxx__I', which is a reserved identifier[bugprone-reserved-identifier,cert-dcl37-c,cert-dcl51-cpp]
C/C++:  /Users/.../xxJNI.cpp:1740:24: note: FIX-IT applied suggested code changes

The code of bugprone-reserved-identifier is located at clang-tools-extra/clang-tidy/bugprone/ReservedIdentifierCheck.cpp.

static std::string collapseConsecutive(StringRef Str, char C) {
std::string Result;
std::unique_copy(Str.begin(), Str.end(), std::back_inserter(Result),
[C](char A, char B) { return A == C && B == C; });
return Result;
}

static bool hasReservedDoubleUnderscore(StringRef Name,
const LangOptions &LangOpts) {
if (LangOpts.CPlusPlus)
return Name.contains("");
return Name.starts_with("");
}

static std::optionalstd::string
getDoubleUnderscoreFixup(StringRef Name, const LangOptions &LangOpts) {
if (hasReservedDoubleUnderscore(Name, LangOpts))
return collapseConsecutive(Name, '_');
return std::nullopt;
}
@forunix forunix changed the title [C++] [Clang-tidy] bugprone-reserved-identifier mistakenly changed JNI API to wrong one [C++] [clang-tidy] bugprone-reserved-identifier mistakenly changed JNI API to wrong one Dec 25, 2024
@EugeneZelenko EugeneZelenko marked this as a duplicate of #121087 Dec 25, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant