From: Eli Bendersky Date: Fri, 20 Jun 2014 13:09:59 +0000 (+0000) Subject: Fix PR20081: Parsing templates in the presence of -x cuda -std=c++11 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=47277ffc39d9b1f068204e70f06fbec2fe0f8c53;p=clang Fix PR20081: Parsing templates in the presence of -x cuda -std=c++11 http://reviews.llvm.org/D4222 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@211357 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Parse/ParseTemplate.cpp b/lib/Parse/ParseTemplate.cpp index 6551fe25da..fa6401f083 100644 --- a/lib/Parse/ParseTemplate.cpp +++ b/lib/Parse/ParseTemplate.cpp @@ -751,7 +751,9 @@ bool Parser::ParseGreaterThanInTemplateList(SourceLocation &RAngleLoc, // This template-id is terminated by a token which starts with a '>'. Outside // C++11, this is now error recovery, and in C++11, this is error recovery if - // the token isn't '>>'. + // the token isn't '>>' or '>>>'. + // '>>>' is for CUDA, where this sequence of characters is parsed into + // tok::greatergreatergreater, rather than two separate tokens. RAngleLoc = Tok.getLocation(); @@ -781,7 +783,8 @@ bool Parser::ParseGreaterThanInTemplateList(SourceLocation &RAngleLoc, Hint2 = FixItHint::CreateInsertion(Next.getLocation(), " "); unsigned DiagId = diag::err_two_right_angle_brackets_need_space; - if (getLangOpts().CPlusPlus11 && Tok.is(tok::greatergreater)) + if (getLangOpts().CPlusPlus11 && + (Tok.is(tok::greatergreater) || Tok.is(tok::greatergreatergreater))) DiagId = diag::warn_cxx98_compat_two_right_angle_brackets; else if (Tok.is(tok::greaterequal)) DiagId = diag::err_right_angle_bracket_equal_needs_space; diff --git a/test/Parser/cuda-kernel-call-c++11.cu b/test/Parser/cuda-kernel-call-c++11.cu new file mode 100644 index 0000000000..8f833f79af --- /dev/null +++ b/test/Parser/cuda-kernel-call-c++11.cu @@ -0,0 +1,20 @@ +// RUN: %clang_cc1 -fsyntax-only -std=c++11 -verify %s + +template struct S {}; +template void f(); + + +void foo(void) { + // In C++11 mode, all of these are expected to parse correctly, and the CUDA + // language should not interfere with that. + + // expected-no-diagnostics + + S>> s3; + + S>>> s4; + + S>>>> s5; + + (void)(&f>>==0); +} diff --git a/test/Parser/cuda-kernel-call.cu b/test/Parser/cuda-kernel-call.cu index 92e46e3aca..1970c558c5 100644 --- a/test/Parser/cuda-kernel-call.cu +++ b/test/Parser/cuda-kernel-call.cu @@ -10,7 +10,8 @@ void foo(void) { foo<<<>>>(); // expected-error {{expected expression}} - S>> s; // expected-error 2{{use '> >'}} + // The following two are parse errors because -std=c++11 is not enabled. + S>> s; // expected-error 2{{use '> >'}} (void)(&f>>==0); // expected-error 2{{use '> >'}} }