vim-patch:8.0.0092

Problem:    C indenting does not support nested namespaces that C++ 17 has.
Solution:   Add check that passes double colon inside a name. (Pauli, closes
            vim/vim#1214)

ca8b8d6956
This commit is contained in:
Lech Lorens
2017-08-20 12:14:27 +02:00
parent b3da396804
commit d2595ba1c4
3 changed files with 61 additions and 14 deletions

View File

@@ -515,34 +515,41 @@ int cin_isscopedecl(char_u *s)
/* Maximum number of lines to search back for a "namespace" line. */ /* Maximum number of lines to search back for a "namespace" line. */
#define FIND_NAMESPACE_LIM 20 #define FIND_NAMESPACE_LIM 20
/* // Recognize a "namespace" scope declaration.
* Recognize a "namespace" scope declaration. static bool cin_is_cpp_namespace(char_u *s)
*/
static int cin_is_cpp_namespace(char_u *s)
{ {
char_u *p; char_u *p;
int has_name = FALSE; bool has_name = false;
bool has_name_start = false;
s = cin_skipcomment(s); s = cin_skipcomment(s);
if (STRNCMP(s, "namespace", 9) == 0 && (s[9] == NUL || !vim_iswordc(s[9]))) { if (STRNCMP(s, "namespace", 9) == 0 && (s[9] == NUL || !vim_iswordc(s[9]))) {
p = cin_skipcomment(skipwhite(s + 9)); p = cin_skipcomment(skipwhite(s + 9));
while (*p != NUL) { while (*p != NUL) {
if (ascii_iswhite(*p)) { if (ascii_iswhite(*p)) {
has_name = TRUE; /* found end of a name */ has_name = true; // found end of a name
p = cin_skipcomment(skipwhite(p)); p = cin_skipcomment(skipwhite(p));
} else if (*p == '{') { } else if (*p == '{') {
break; break;
} else if (vim_iswordc(*p)) { } else if (vim_iswordc(*p)) {
if (has_name) has_name_start = true;
return FALSE; /* word character after skipping past name */ if (has_name) {
++p; return false; // word character after skipping past name
}
p++;
} else if (p[0] == ':' && p[1] == ':' && vim_iswordc(p[2])) {
if (!has_name_start || has_name) {
return false;
}
// C++ 17 nested namespace
p += 3;
} else { } else {
return FALSE; return false;
} }
} }
return TRUE; return true;
} }
return FALSE; return false;
} }
/* /*

View File

@@ -860,7 +860,7 @@ static const int included_patches[] = {
// 95 NA // 95 NA
// 94 NA // 94 NA
// 93 NA // 93 NA
// 92, 92,
// 91, // 91,
90, 90,
// 89 NA // 89 NA

View File

@@ -3915,6 +3915,26 @@ describe('cindent', function()
{ {
111111111111111111; 111111111111111111;
} }
namespace test::cpp17
{
111111111111111111;
}
namespace ::incorrectcpp17
{
111111111111111111;
}
namespace test::incorrectcpp17::
{
111111111111111111;
}
namespace test:incorrectcpp17
{
111111111111111111;
}
namespace test:::incorrectcpp17
{
111111111111111111;
}
namespace{ namespace{
111111111111111111; 111111111111111111;
} }
@@ -3986,6 +4006,26 @@ describe('cindent', function()
{ {
111111111111111111; 111111111111111111;
} }
namespace test::cpp17
{
111111111111111111;
}
namespace ::incorrectcpp17
{
111111111111111111;
}
namespace test::incorrectcpp17::
{
111111111111111111;
}
namespace test:incorrectcpp17
{
111111111111111111;
}
namespace test:::incorrectcpp17
{
111111111111111111;
}
namespace{ namespace{
111111111111111111; 111111111111111111;
} }