Issue 121087
Summary [C++] [Clang-tidy] bugprone-reserved-identifier mistakenly changed JNI API
Labels clang-tidy
Assignees
Reporter forunix
    Please help to fix the problem for bugprone-reserved-identifier of clang-tidy.

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

As an example it will change Java_cn_huolala_nav_kit_HLLNVBusinessJNI_nativeSwitchParallelRoad__I to Java_cn_huolala_nav_kit_HLLNVBusinessJNI_nativeSwitchParallelRoad_I.

The build info is as follows.
`C/C++: /Users/wudizhiwang/Repos/hll-nav-demo/hll-nav-business/main/src/android/HLLNVBusinessJNI.cpp:1740:24: warning: declaration uses identifier 'Java_cn_huolala_nav_kit_HLLNVBusinessJNI_nativeSwitchParallelRoad__I', which is a reserved identifier [bugprone-reserved-identifier,cert-dcl37-c,cert-dcl51-cpp]
C/C++: /Users/wudizhiwang/Repos/hll-nav-demo/hll-nav-business/main/src/android/HLLNVBusinessJNI.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::optional<std::string>
getDoubleUnderscoreFixup(StringRef Name, const LangOptions &LangOpts) {
  if (hasReservedDoubleUnderscore(Name, LangOpts))
    return collapseConsecutive(Name, '_');
  return std::nullopt;
}`
_______________________________________________
llvm-bugs mailing list
llvm-bugs@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to