boostorg / boostorg/wave

Failing to emit line directive if included file has a #if or #define on the first line

Open
#222 2 comments 0 reactions 0 assignees View on GitHub
Dominant language
C++
Stars
29
Forks
55
PR merge metrics
No merged PRs in 30d

Description

Wave is not emitting the line directive if the first line in the included file is a `#if` or `#ifdef` that evaluates true and has content in its block. Likewise, it won't emit the line directive if the first line is a `#define`. This issue only occurs if there are not multiple `#define` or `#if` occurring on subsequent lines.
When using `default_preprocessing_hooks`, the above applies if the `#if`/`#ifdef`/`#define` is the first non-empty line or non-comment line. Essentially, if the directive immediately precedes the first content emitted from the included file. With `eat_whitespace`, the directive must be on the very first line of the include file to exhibit the issue.

Not sure if I've explained it very well, but I think an example will help better demonstrate the issue.

**Example:**
_a.cpp_
```
#include "if.h"
#include "def.h"
test
```
_if.h_
```
#if 1 //This must be on the first line for eat_whitespace, can be on 2nd, 3rd etc, for default_preprocessing_hooks as long as it's whitespace before it
if_h
#endif
```
_def.h_
```
#define A
def_h
```

**Resulting preprocessed file:**
_a.preproc_
```

if_h

def_h
```

**Expected output:**
```
#line 2 "if.h"
if_h
#line 2 "def.h"
def_h
```

As mentioned, the line directives do get emitted correctly if the include file is something like this:
```
#define A
#define B
content
```
So it's only occurring when there's a single directive at the beginning.

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.