[clang-rename] check whether -new-name is valid identifier in C++17

llvm-svn: 276259
This commit is contained in:
Kirill Bobyrev 2016-07-21 10:21:31 +00:00
parent 8390d50e9c
commit 08c588c73a
3 changed files with 15 additions and 2 deletions

View File

@ -99,7 +99,18 @@ int main(int argc, const char **argv) {
// Check the arguments for correctness.
if (NewName.empty()) {
errs() << "clang-rename: no new name provided.\n\n";
errs() << "ERROR: no new name provided.\n\n";
exit(1);
}
// Check if NewName is a valid identifier in C++17.
LangOptions Options;
Options.CPlusPlus = true;
Options.CPlusPlus1z = true;
IdentifierTable Table(Options);
auto NewNameTokKind = Table.get(NewName).getTokenID();
if (!tok::isAnyIdentifier(NewNameTokKind)) {
errs() << "ERROR: new name is not a valid identifier in C++17.\n\n";
exit(1);
}

View File

@ -0,0 +1,2 @@
// RUN: not clang-rename -new-name=class -offset=133 %s 2>&1 | FileCheck %s
// CHECK: ERROR: new name is not a valid identifier in C++17.

View File

@ -1,4 +1,4 @@
// Check for an error while -new-name argument has not been passed to
// clang-rename.
// RUN: not clang-rename -offset=133 %s 2>&1 | FileCheck %s
// CHECK: clang-rename: no new name provided.
// CHECK: ERROR: no new name provided.