mirror of
https://github.com/cc65/cc65.git
synced 2024-12-22 12:30:41 +00:00
Fix macro preprocessing for #include. Arguments enclosed in "" or <> must not
be preprocessed. See ISO/IEC 9899 1990 (E) section 6.8.2.
This commit is contained in:
parent
b688cfa0c0
commit
b4aef6eac4
@ -2812,11 +2812,30 @@ static void DoInclude (void)
|
||||
InputType IT;
|
||||
StrBuf Filename = AUTO_STRBUF_INITIALIZER;
|
||||
|
||||
/* Macro-replace a single line with special support for <filename> */
|
||||
SB_Clear (MLine);
|
||||
PreprocessDirective (Line, MLine, MSM_TOK_HEADER);
|
||||
/* Skip whitespace so the input pointer points to the argument */
|
||||
SkipWhitespace (0);
|
||||
|
||||
/* Read from the processed line */
|
||||
/* We may have three forms of the #include directive:
|
||||
**
|
||||
** - # include "q-char-sequence" new-line
|
||||
** - # include <h-char-sequence> new-line
|
||||
** - # include pp-tokens new-line
|
||||
**
|
||||
** The former two are processed as is while the latter is preprocessed and
|
||||
** must then resemble one of the first two forms.
|
||||
*/
|
||||
if (CurC == '"' || CurC == '<') {
|
||||
/* Copy the argument part over to MLine */
|
||||
unsigned Start = SB_GetIndex (Line);
|
||||
unsigned Length = SB_GetLen (Line) - Start;
|
||||
SB_Slice (MLine, Line, Start, Length);
|
||||
} else {
|
||||
/* Macro-replace a single line with special support for <filename> */
|
||||
SB_Clear (MLine);
|
||||
PreprocessDirective (Line, MLine, MSM_TOK_HEADER);
|
||||
}
|
||||
|
||||
/* Read from the copied/preprocessed line */
|
||||
SB_Reset (MLine);
|
||||
MLine = InitLine (MLine);
|
||||
|
||||
|
10
test/val/bug2458.c
Normal file
10
test/val/bug2458.c
Normal file
@ -0,0 +1,10 @@
|
||||
#define str(arg) #arg
|
||||
#include str(bug2458.h) /* Ok, macro replacement */
|
||||
|
||||
#define string foo
|
||||
#include <string.h> /* Ok, no macro replacement */
|
||||
|
||||
int main()
|
||||
{
|
||||
return 0;
|
||||
}
|
1
test/val/bug2458.h
Normal file
1
test/val/bug2458.h
Normal file
@ -0,0 +1 @@
|
||||
|
Loading…
Reference in New Issue
Block a user