Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 329153

Summary: add checker for digraphs and trigraphs.
Product: [Tools] CDT Reporter: Vasiliy Dybala <dibalavs>
Component: cdt-codanAssignee: CDT Codan Inbox <cdt-codan-inbox>
Status: RESOLVED INVALID QA Contact: Elena Laskavaia <elaskavaia.cdt>
Severity: enhancement    
Priority: P3 CC: cdtdoug, yevshif, zeratul976
Version: 8.0   
Target Milestone: ---   
Hardware: PC   
OS: Windows 7   
Whiteboard:
Attachments:
Description Flags
Checker + fixes none

Description Vasiliy Dybala CLA 2010-10-31 02:32:45 EDT
Build Identifier: 201010290004

1. write code:

const int var = 1;
namespace
{
  const int var = 2;

  template<int c> void f(){}
  void test()
  {
    f<::var>();
  }
}

2. at line "f<::var>();" eclipse shows uninformative error "syntax error.". But a few people use di and trigraphs (I don't know anyone who uses them) and they are may don't know that symbols <: has another meaning.
 
The idea is add checker that can say user friendly message, for example: "Syntax error. Found '<:' digraph. Please fix to '< :'"

Reproducible: Always
Comment 1 Tomasz Wesolowski CLA 2011-06-19 19:03:06 EDT
Let's think for a second here.

The "Syntax error" marker comes from the parser, since the parser understands digraphs / trigraphs correctly and is unable to parse the code.

The parser has to support digraphs and trigraphs, because it needs to be able to handle any legacy code which has them in.

It is indeed possible to have a checker which would look for digraphs/trigraphs- but what then? We can't always warn about them since I they might be desired in some code. Some compilers (like GCC on default settings) ignore di/trigraphs, but I believe there's no accessible project-specific setting for that, so that we could set the parser in the right mode automatically.

What I'd actually like to see is separate syntax coloring for di/trigraphs.
Comment 2 Tomasz Wesolowski CLA 2011-08-16 17:10:16 EDT
Created attachment 201608 [details]
Checker + fixes

Actually I have serious second thoughts about them being "desired in some code"... Anyway- here's the checker + two quick fixes:
- replace the sequence by "normal" token
- escape the sequence 

Trigraphs are checked before tokenisation, digraphs - after.

The patch also does a little cleanup w/r/t localisation in a couple of other quick fixes (there were two Messages.properties when there should've been one).

Do we need junits for this checker?
Comment 3 Nathan Ridge CLA 2013-08-24 17:54:10 EDT
According to the standard, the code in comment 0 is valid. We no longer give a syntax error for it (see bug 398254).

Do we still need this checker?
Comment 4 Nathan Ridge CLA 2017-01-07 18:47:06 EST
Closing per comment 3.