接続数

COUNTER366899FROM 2012/5/16

MISRA-C diary(C言語日誌)

MISRA-C >> Article details

2014/06/12

C++N3242, 2011 (6) 2 Lexical conventions 2.14 Literals 2.14.5 String literals

Tweet ThisSend to Facebook | by kaizen
// 1 filename:cpp2011-2-14-5.cpp
// ver 0.1 June.12, 2014
//
// 2 original examples and/or notes:
// (c) ISO/IEC JTC1 SC22 WG21 N3242, April 12, 2011
// http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2011/n3242.pdf
// 2 Lexical conventions 2.14 Literals 2.14.5 String literals
//
// 3 compile and output mechanism:
// (c) Ogawa Kiyoshi, kaizen@gifu-u.ac.jp,
//
// 4 compile errors and/or wornings:
// 4.1(c) Apple LLVM version 5.1 (clang-503.0.40) (based on LLVM 3.4svn)
// Target: x86_64-apple-darwin13.2.0,  Thread model: posix
// Command/Options: c++ -std=c++11 -stdlib=libc++ -Wall cpp2011-2-14-5.cpp 
// (c) LLVM 2003-2009 University of Illinois at Urbana-Champaign.

// 4.2. g++-4.9 (GCC) 4.9.0 20131229 (experimental)
// Copyright (C) 2013 Free Software Foundation, Inc.
// This is free software; see the source for copying conditions.  There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
// http://gcc.gnu.org/onlinedocs/gcc/Standards.html
// Command/Options: g++-4.9  -std=c++11  -Wall cpp2011-2-14-5.cpp 
// g++-4.9: error: unrecognized command line option '-stdlib=libc++'
// Configuration:brew install gcc49
//
// 4.3. Visual Studio Express 2013, 
// (c) Microsoft http://www.visualstudio.com/
// SPEC:
// Windows 7, .NET Framework
// (c) VMware, Inc.
// VMWare fusion 6
//
// 5. Hardware:  MacBook Pro, 
//(c) Intel http://ark.intel.com/products/37006/
//Core 2 Duo 2.53GHz, 8GB, 1067MHz DDR3
//
// 6. Special Thanks: Upper organizatios and 
// ITSCJ/IPSJ http://www.itscj.ipsj.or.jp/itscj_english/index.html
// NPO SESSAME project, http://www.sessame.jp/workinggroup/WorkingGroup3/
// Toyo Corporation, http://www.toyo.co.jp/English/
// Japan Standard Association, http://bit.ly/1lzykg1
// NPO TOPPERS project, https://www.toppers.jp/asp-d-download.html
// Daido Universcity, http://www.daido-it.ac.jp/gakubugakka/computer/index.html
// WITZ Co.Ltd., http://www.witz-inc.co.jp/products/solution/solution.html
// SevenWise.co., http://www.7ws.co.jp/index.html
// TOYOTA Motor Corporation, http://toyota.jp/
// IT planning Inc., http://www.itpl.co.jp/en/index.html
// DENSO Corporation, http://www.globaldenso.com/en/
// Aisin Seiki co. Ltd., http://www.aisin.com/
// Spancion Inc., http://www.spansion.com/
// Yazaki Corporation, http://www.yazaki-group.com/global/
// Pananosic Corporation, http://www.panasonic.net/
// SWEST: Summer Workshop on Embedded System Technologies , http://swest.toppers.jp
// CEST: Consortium for Embedded System Technology, http://www.ertl.jp/CEST/
// JUSE: Union of Japanese Scientists and Engineers, http://www.juse.or.jp/e/
// OSC:Open Source Conference, http://www.ospn.jp/

#include <iostream>
#include <string.h>
#include <cassert>

using namespace std;
#define R "x" // from 2.5 

int main()
{
const char *p = R"(a\
b
c)";

//assert(std::strcmp(p, "a\\\nb\nc") == 0); cpp2011-2-14-5.cpp:67:8: error: 'strcmp' is not a member of 'std'
assert(strcmp(p, "a\\\nb\nc") == 0);

cout << p <<std::endl;
const char *p1 = R")\
a"
)a";
cout << p1 <<std::endl;
// is equivalent 
cout << "\n)\\\na\"\n"  <<std::endl;

const char *p2 =R"(??)" ;
cout << p2 <<std::endl;
//is equivalent to 
cout << "\?\?"  <<std::endl;

const char *p3 = R"#(
)??="
)#"  ;
cout << p3 <<std::endl;
//is equivalent to 
cout <<"\n)\?\?=\"\n" <<std::endl;
return 0;
}
// 1. error 
// 1.1 LLVM  -std=c++11


// 1.2 gcc4.9 -std=c++11

// 2. output -std=c++03

llvm, gcc, -std=c++11, c++03のいずれでもまだコンパイルエラーが取れてない。次に進んでから戻る予定。

 ../cppall.sh cpp2011-2-14-5

$ clang++ cpp2011-2-14-5.cpp -std=c++03 -Wall

cpp2011-2-14-5.cpp:67:18: warning: missing terminating '"' character [-Winvalid-pp-token]

const char *p = R"(a\

                 ^

cpp2011-2-14-5.cpp:67:18: error: expected ';' at end of declaration

const char *p = R"(a\

                 ^

                 ;

cpp2011-2-14-5.cpp:69:3: warning: missing terminating '"' character [-Winvalid-pp-token]

c)";

  ^

cpp2011-2-14-5.cpp:76:3: error: expected ';' at end of declaration

a"

  ^

  ;

cpp2011-2-14-5.cpp:77:3: warning: missing terminating '"' character [-Winvalid-pp-token]

)a";

  ^

cpp2011-2-14-5.cpp:82:20: warning: trigraph converted to ']' character [-Wtrigraphs]

const char *p2 =R"(??)" ;

                   ^

cpp2011-2-14-5.cpp:87:19: warning: missing terminating '"' character [-Winvalid-pp-token]

const char *p3 = R"#(

                  ^

cpp2011-2-14-5.cpp:87:19: error: expected ';' at end of declaration

const char *p3 = R"#(

                  ^

                  ;

cpp2011-2-14-5.cpp:88:2: warning: trigraph converted to '#' character [-Wtrigraphs]

)??="

 ^

cpp2011-2-14-5.cpp:88:5: warning: missing terminating '"' character [-Winvalid-pp-token]

)??="

    ^

cpp2011-2-14-5.cpp:89:3: warning: missing terminating '"' character [-Winvalid-pp-token]

)#"  ;

  ^

8 warnings and 3 errors generated.

$ clang++ cpp2011-2-14-5.cpp -std=c++11 -Wall

cpp2011-2-14-5.cpp:75:20: error: invalid character ')' character in raw string delimiter; use

      PREFIX( )PREFIX to delimit raw string

const char *p1 = R")\

                   ^

cpp2011-2-14-5.cpp:75:18: error: expected expression

const char *p1 = R")\

                 ^

cpp2011-2-14-5.cpp:77:3: warning: missing terminating '"' character [-Winvalid-pp-token]

)a";

  ^

1 warning and 2 errors generated.

$ clang++ cpp2011-2-14-5.cpp -std=c++17 -Wall

cpp2011-2-14-5.cpp:75:20: error: invalid character ')' character in raw string delimiter; use

      PREFIX( )PREFIX to delimit raw string

const char *p1 = R")\

                   ^

cpp2011-2-14-5.cpp:75:18: error: expected expression

const char *p1 = R")\

                 ^

cpp2011-2-14-5.cpp:77:3: warning: missing terminating '"' character [-Winvalid-pp-token]

)a";

  ^

1 warning and 2 errors generated.


$ g++-7 cpp2011-2-14-5.cpp -std=c++03  -Wall

cpp2011-2-14-5.cpp:67:18:warning: missing terminating " character

 const char *p = R"(a\

                  ^

cpp2011-2-14-5.cpp:67:18:error: missing terminating " character

 const char *p = R"(a\

                  ^~~~

 b

 ~                 

cpp2011-2-14-5.cpp:69:3:warning: missing terminating " character

 c)";

   ^

cpp2011-2-14-5.cpp:69:3:error: missing terminating " character

 c)";

   ^~

cpp2011-2-14-5.cpp:77:3:warning: missing terminating " character

 )a";

   ^

cpp2011-2-14-5.cpp:77:3:error: missing terminating " character

 )a";

   ^~

cpp2011-2-14-5.cpp:82:20:warning: trigraph ??) converted to ] [-Wtrigraphs]

 const char *p2 =R"(??)" ;

                     

cpp2011-2-14-5.cpp:87:19:warning: missing terminating " character

 const char *p3 = R"#(

                   ^

cpp2011-2-14-5.cpp:87:19:error: missing terminating " character

 const char *p3 = R"#(

                   ^~~

cpp2011-2-14-5.cpp:88:2:warning: trigraph ??= converted to # [-Wtrigraphs]

 )??="

   

cpp2011-2-14-5.cpp:88:2:error: stray '#' in program

 )??="

  ^

cpp2011-2-14-5.cpp:88:3:warning: missing terminating " character

 )??="

   ^

cpp2011-2-14-5.cpp:88:3:error: missing terminating " character

cpp2011-2-14-5.cpp:89:2:error: stray '#' in program

 )#"  ;

  ^

cpp2011-2-14-5.cpp:89:3:warning: missing terminating " character

 )#"  ;

   ^

cpp2011-2-14-5.cpp:89:3:error: missing terminating " character

 )#"  ;

   ^~~~

cpp2011-2-14-5.cpp: In function 'int main()':

cpp2011-2-14-5.cpp:69:1:error: expected ',' or ';' before 'c'

 c)";

 ^

cpp2011-2-14-5.cpp:77:1:error: expected ',' or ';' before ')' token

 )a";

 ^

cpp2011-2-14-5.cpp:88:1:error: expected ',' or ';' before ')' token

 )??="

 ^

cpp2011-2-14-5.cpp:75:13:warning: unused variable 'p1' [-Wunused-variable]

 const char *p1 = R")\

             ^~

cpp2011-2-14-5.cpp:87:13:warning: unused variable 'p3' [-Wunused-variable]

 const char *p3 = R"#(

             ^~


$ g++-7 cpp2011-2-14-5.cpp -std=c++11  -Wall

cpp2011-2-14-5.cpp:75:21:error: invalid character ')' in raw string delimiter

 const char *p1 = R")\

                  ^   

cpp2011-2-14-5.cpp:75:18:error: stray 'R' in program

cpp2011-2-14-5.cpp:77:3:warning: missing terminating " character

 )a";

   ^

cpp2011-2-14-5.cpp:77:3:error: missing terminating " character

 )a";

   ^~

cpp2011-2-14-5.cpp: In function 'int main()':

cpp2011-2-14-5.cpp:77:1:error: expected ',' or ';' before ')' token

 )a";

 ^

cpp2011-2-14-5.cpp:75:13:warning: unused variable 'p1' [-Wunused-variable]

 const char *p1 = R")\

             ^~


$ g++-7 cpp2011-2-14-5.cpp -std=c++17  -Wall

cpp2011-2-14-5.cpp:75:21:error: invalid character ')' in raw string delimiter

 const char *p1 = R")\

                  ^   

cpp2011-2-14-5.cpp:75:18:error: stray 'R' in program

cpp2011-2-14-5.cpp:77:3:warning: missing terminating " character

 )a";

   ^

cpp2011-2-14-5.cpp:77:3:error: missing terminating " character

 )a";

   ^~

cpp2011-2-14-5.cpp: In function 'int main()':

cpp2011-2-14-5.cpp:77:1:error: expected ',' or ';' before ')' token

 )a";

 ^

cpp2011-2-14-5.cpp:75:13:warning: unused variable 'p1' [-Wunused-variable]

 const char *p1 = R")\

             ^~

----------------

#include <iostream>

#include <string.h>

#include <cassert>

#define msg "C++n32422 Lexical conventions 2.14 Literals 2.14.5 String literals"


using namespace std;

#define R "x" // from 2.5 


int main()

{

  const char *p = R"(a\

b

c)";


//assert(std::strcmp(p, "a\\\nb\nc") == 0); cpp2011-2-14-5.cpp:67:8: error: 'strcmp' is not a member of 'std'

  assert(strcmp(p, "a\\\nb\nc") == 0);


  cout << p <<std::endl;

  cout << msg <<std::endl;

  return  EXIT_SUCCESS;;

}

----------------

$ ../cppall.sh cpp2011-2-14-5a

$ clang++ cpp2011-2-14-5a.cpp -std=c++03 -Wall

cpp2011-2-14-5a.cpp:67:18: warning: missing terminating '"' character [-Winvalid-pp-token]

const char *p = R"(a\

                 ^

cpp2011-2-14-5a.cpp:67:18: error: expected ';' at end of declaration

const char *p = R"(a\

                 ^

                 ;

cpp2011-2-14-5a.cpp:69:3: warning: missing terminating '"' character [-Winvalid-pp-token]

c)";

  ^

2 warnings and 1 error generated.

$ clang++ cpp2011-2-14-5a.cpp -std=c++11 -Wall

a\

b

c

C++n32422 Lexical conventions 2.14 Literals 2.14.5 String literals

$ clang++ cpp2011-2-14-5a.cpp -std=c++17 -Wall

a\

b

c

C++n32422 Lexical conventions 2.14 Literals 2.14.5 String literals


$ g++-7 cpp2011-2-14-5a.cpp -std=c++03  -Wall

cpp2011-2-14-5a.cpp:67:18:warning: missing terminating " character

 const char *p = R"(a\

                  ^

cpp2011-2-14-5a.cpp:67:18:error: missing terminating " character

 const char *p = R"(a\

                  ^~~~

 b

 ~                 

cpp2011-2-14-5a.cpp:69:3:warning: missing terminating " character

 c)";

   ^

cpp2011-2-14-5a.cpp:69:3:error: missing terminating " character

 c)";

   ^~

cpp2011-2-14-5a.cpp: In function 'int main()':

cpp2011-2-14-5a.cpp:69:1:error: expected ',' or ';' before 'c'

 c)";

 ^


$ g++-7 cpp2011-2-14-5a.cpp -std=c++11  -Wall

a\

b

c

C++n32422 Lexical conventions 2.14 Literals 2.14.5 String literals


$ g++-7 cpp2011-2-14-5a.cpp -std=c++17  -Wall

a\

b

c

C++n32422 Lexical conventions 2.14 Literals 2.14.5 String literals

----------
----cpp2011-2-14-5b.cpp

#define msg "C++n32422 Lexical conventions 2.14 Literals 2.14.5 String literals"


#include <iostream>

#include <string.h>

#include <cassert>


using namespace std;

#define R "x" // from 2.5


int main()

{

const char *p1 = R"a(\

)\

a"

)a";

cout << p1 <<std::endl;

// is equivalent

cout << "\n)\\\na\"\n"  <<std::endl;


  cout << msg <<std::endl;

  return  EXIT_SUCCESS;;

return 0;

}

------

$ ../cppall.sh cpp2011-2-14-5b

$ clang++ cpp2011-2-14-5b.cpp -std=c++03 -Wall

cpp2011-2-14-5b.cpp:69:3: error: expected ';' at end of declaration

a"

  ^

  ;

cpp2011-2-14-5b.cpp:70:3: warning: missing terminating '"' character [-Winvalid-pp-token]

)a";

  ^

1 warning and 1 error generated.

$ clang++ cpp2011-2-14-5b.cpp -std=c++11 -Wall

\

)\

a"



)\

a"


C++n32422 Lexical conventions 2.14 Literals 2.14.5 String literals

$ clang++ cpp2011-2-14-5b.cpp -std=c++17 -Wall

\

)\

a"



)\

a"


C++n32422 Lexical conventions 2.14 Literals 2.14.5 String literals


$ g++-7 cpp2011-2-14-5b.cpp -std=c++03  -Wall

cpp2011-2-14-5b.cpp:70:3:warning: missing terminating " character

 )a";

   ^

cpp2011-2-14-5b.cpp:70:3:error: missing terminating " character

 )a";

   ^~

cpp2011-2-14-5b.cpp: In function 'int main()':

cpp2011-2-14-5b.cpp:70:1:error: expected ',' or ';' before ')' token

 )a";

 ^

cpp2011-2-14-5b.cpp:67:13:warning: unused variable 'p1' [-Wunused-variable]

 const char *p1 = R"a(\

             ^~


$ g++-7 cpp2011-2-14-5b.cpp -std=c++11  -Wall

\

)\

a"



)\

a"


C++n32422 Lexical conventions 2.14 Literals 2.14.5 String literals


$ g++-7 cpp2011-2-14-5b.cpp -std=c++17  -Wall

\

)\

a"



)\

a"


C++n32422 Lexical conventions 2.14 Literals 2.14.5 String literals

---cpp2011-2-14-5c.cpp

#include <iostream>

#include <string.h>

#include <cassert>


using namespace std;

#define R "x" // from 2.5 


int main()

{

  const char *p = R"(a\

b

c)";


  const char *p2 =R"(??)" ;

  cout << p2 <<std::endl;

//is equivalent to

  cout << "\?\?"  <<std::endl;


  const char *p3 = R"#(

)??="

)#"  ;

cout << p3 <<std::endl;

//is equivalent to 

cout <<"\n)\?\?=\"\n" <<std::endl;

return 0;

}


----

$ ../cppall.sh cpp2011-2-14-5c

$ clang++ cpp2011-2-14-5c.cpp -std=c++03 -Wall

cpp2011-2-14-5c.cpp:67:18: warning: missing terminating '"' character [-Winvalid-pp-token]

const char *p = R"(a\

                 ^

cpp2011-2-14-5c.cpp:67:18: error: expected ';' at end of declaration

const char *p = R"(a\

                 ^

                 ;

cpp2011-2-14-5c.cpp:69:3: warning: missing terminating '"' character [-Winvalid-pp-token]

c)";

  ^

cpp2011-2-14-5c.cpp:71:20: warning: trigraph converted to ']' character [-Wtrigraphs]

const char *p2 =R"(??)" ;

                   ^

cpp2011-2-14-5c.cpp:72:9: error: use of undeclared identifier 'p2'

cout << p2 <<std::endl;

        ^

cpp2011-2-14-5c.cpp:76:19: warning: missing terminating '"' character [-Winvalid-pp-token]

const char *p3 = R"#(

                  ^

cpp2011-2-14-5c.cpp:76:19: error: expected ';' at end of declaration

const char *p3 = R"#(

                  ^

                  ;

cpp2011-2-14-5c.cpp:77:2: warning: trigraph converted to '#' character [-Wtrigraphs]

)??="

 ^

cpp2011-2-14-5c.cpp:77:5: warning: missing terminating '"' character [-Winvalid-pp-token]

)??="

    ^

cpp2011-2-14-5c.cpp:78:3: warning: missing terminating '"' character [-Winvalid-pp-token]

)#"  ;

  ^

7 warnings and 3 errors generated.

$ clang++ cpp2011-2-14-5c.cpp -std=c++11 -Wall

cpp2011-2-14-5c.cpp:67:13: warning: unused variable 'p' [-Wunused-variable]

const char *p = R"(a\

            ^

1 warning generated.

??

??


)??="



)??="


$ clang++ cpp2011-2-14-5c.cpp -std=c++17 -Wall

cpp2011-2-14-5c.cpp:67:13: warning: unused variable 'p' [-Wunused-variable]

const char *p = R"(a\

            ^

1 warning generated.

??

??


)??="



)??="



$ g++-7 cpp2011-2-14-5c.cpp -std=c++03  -Wall

cpp2011-2-14-5c.cpp:67:18:warning: missing terminating " character

 const char *p = R"(a\

                  ^

cpp2011-2-14-5c.cpp:67:18:error: missing terminating " character

 const char *p = R"(a\

                  ^~~~

 b

 ~                 

cpp2011-2-14-5c.cpp:69:3:warning: missing terminating " character

 c)";

   ^

cpp2011-2-14-5c.cpp:69:3:error: missing terminating " character

 c)";

   ^~

cpp2011-2-14-5c.cpp:71:20:warning: trigraph ??) converted to ] [-Wtrigraphs]

 const char *p2 =R"(??)" ;

                     

cpp2011-2-14-5c.cpp:76:19:warning: missing terminating " character

 const char *p3 = R"#(

                   ^

cpp2011-2-14-5c.cpp:76:19:error: missing terminating " character

 const char *p3 = R"#(

                   ^~~

cpp2011-2-14-5c.cpp:77:2:warning: trigraph ??= converted to # [-Wtrigraphs]

 )??="

   

cpp2011-2-14-5c.cpp:77:2:error: stray '#' in program

 )??="

  ^

cpp2011-2-14-5c.cpp:77:3:warning: missing terminating " character

 )??="

   ^

cpp2011-2-14-5c.cpp:77:3:error: missing terminating " character

cpp2011-2-14-5c.cpp:78:2:error: stray '#' in program

 )#"  ;

  ^

cpp2011-2-14-5c.cpp:78:3:warning: missing terminating " character

 )#"  ;

   ^

cpp2011-2-14-5c.cpp:78:3:error: missing terminating " character

 )#"  ;

   ^~~~

cpp2011-2-14-5c.cpp: In function 'int main()':

cpp2011-2-14-5c.cpp:69:1:error: expected ',' or ';' before 'c'

 c)";

 ^

cpp2011-2-14-5c.cpp:72:9:error: 'p2' was not declared in this scope

 cout << p2 <<std::endl;

         ^~

cpp2011-2-14-5c.cpp:72:9:note: suggested alternative: 'p'

 cout << p2 <<std::endl;

         ^~

         p

cpp2011-2-14-5c.cpp:77:1:error: expected ',' or ';' before ')' token

 )??="

 ^

cpp2011-2-14-5c.cpp:67:13:warning: unused variable 'p' [-Wunused-variable]

 const char *p = R"(a\

             ^

cpp2011-2-14-5c.cpp:76:13:warning: unused variable 'p3' [-Wunused-variable]

 const char *p3 = R"#(

             ^~


$ g++-7 cpp2011-2-14-5c.cpp -std=c++11  -Wall

cpp2011-2-14-5c.cpp: In function 'int main()':

cpp2011-2-14-5c.cpp:67:13:warning: unused variable 'p' [-Wunused-variable]

 const char *p = R"(a\

             ^

??

??


)??="



)??="



$ g++-7 cpp2011-2-14-5c.cpp -std=c++17  -Wall

cpp2011-2-14-5c.cpp: In function 'int main()':

cpp2011-2-14-5c.cpp:67:13:warning: unused variable 'p' [-Wunused-variable]

 const char *p = R"(a\

             ^

??

??


)??="



)??="


----
<この稿は書きかけです。順次追記しています。>
twitter:@kaizen_nagoya
08:20 | Impressed! | Voted(0) | Comment(0)