Commit ba064df2 authored by neil's avatar neil
Browse files

* cpplex.c: Fix trigraph replacement within strings.

	* gcc.dg/cpp/lexident.c, gcc.dg/cpp/lexnum.c,
	  gcc.dg/cpp/lexstrng.c: New tests.


git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@34868 138bc75d-0d04-0410-961f-82ee72b054a4
parent 0ab5f3fb
2000-07-05 Neil Booth <NeilB@earthling.net>
* cpplex.c: Fix trigraph replacement within strings.
2000-07-04 Kaveh R. Ghazi <ghazi@caip.rutgers.edu>
 
* rs6000/aix.h (ASM_GENERATE_INTERNAL_LABEL): Fix format specifier.
......
......@@ -853,7 +853,7 @@ trigraph_replace (pfile, src, limit)
/* Starting with src[1], find two consecutive '?'. The case of no
trigraphs is streamlined. */
for (; src + 1 < limit; src += 2)
for (src++; src + 1 < limit; src += 2)
{
if (src[0] != '?')
continue;
......
2000-07-05 Neil Booth <NeilB@earthling.net>
* gcc.dg/cpp/lexident.c, gcc.dg/cpp/lexnum.c,
gcc.dg/cpp/lexstrng.c: New tests.
2000-07-04 Neil Booth <NeilB@earthling.net>
* gcc.dg/cpp/macro1.c: Add more macro expansion tests.
......
/* Copyright (C) 2000 Free Software Foundation, Inc. */
/* { dg-do preprocess } */
/* { dg-options "-trigraphs" } */
/* Test lexing of identifiers. */
/* Escaped newlines, _ and $ in identifiers. */
#def\
\
ine foo_
#d\
ef??/
in\
e b\
a$r
#ifndef foo_
#error foo_
#endif
#ifndef ba$r
#error ba$r
#endif
/* Copyright (C) 2000 Free Software Foundation, Inc. */
/* { dg-do run } */
/* { dg-options "-trigraphs" } */
/* Test lexing of numbers. */
extern int puts (const char *);
extern void abort (void);
#define err(str) do { puts(str); abort(); } while (0)
/* Escaped newlines. */
#define foo 12\
3\
\
4??/
5
#if foo != 12345
#error foo
#endif
int main (int argc, char *argv[])
{
double a = 5.;
double x = .5;
/* Decimal points, including initially and immediately before and
after an escaped newline. */
if (a != 5)
err ("a");
if (x != .\
5)
err ("x != .5");
x = 25\
.\
6;
if (x != 25.6)
err ("x != 25.6");
/* Test exponentials and their signs. A buggy lexer is more likely
to fail the compile, but never mind. */
if (250 != 25e+1 || 250 != 25e1 || 250 != 2500e-1)
err ("exponentials");
/* Todo: p exponentials, and how to test preprocessing number
tokenisation? */
return 0;
}
/* Copyright (C) 2000 Free Software Foundation, Inc. */
/* { dg-do run } */
/* { dg-options "-trigraphs" } */
/* Test lexing of strings and character constants. */
#include <string.h>
#ifndef __WCHAR_TYPE__
#define __WCHAR_TYPE__ int
#endif
typedef __WCHAR_TYPE__ wchar_t;
extern int strcmp (const char *, const char *);
extern int puts (const char *);
extern void abort (void);
#define err(str) do { puts(str); abort(); } while (0)
/* Escaped newlines. */
const char *str1 = "s\
t\
\
r??/
1";
const char x = '\
??/
b';
/* Test escaped terminators. */
const char *term = "\"\\\"\\";
const char termc = '\'';
const char *terms = "'";
/* Test wide strings and chars are lexed. */
const wchar_t wchar = L'w';
const wchar_t* wstring = L"wide string";
/* Test all 9 trigraphs embedded in a string. Test trigraphs do not
survive an embedded backslash newline. Test trigraphs preceded by
a '?' are still noticed. */
const char *t = "??/\??<??>??=??)??\
(??(??!??'??-???=???/
?-";
int main (int argc, char *argv[])
{
if (strcmp (str1, "str 1"))
err ("str1");
if (x != 'b')
err ("b");
/* We have to split the string up to avoid trigraph replacement
here. Split the 2 trigraphs after both 1 and 2 ?s; just doing
this exposed a bug in the initial release of the tokenized lexer. */
if (strcmp (t, "\\{}#]?" "?([|^~?#??" "-"))
err ("Embedded trigraphs");
if (term[0] != '"' || term[1] != '\\' || term[2] != '"'
|| term[3] != '\\' || term[4] != '\0')
err ("Escaped string terminators");
if (termc != terms[0])
err ("Escaped character constant terminator");
return 0;
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment