Skip to content

Using declaration in namespace in header is mishandled #752

@vmiklos

Description

@vmiklos

Hi,

Steps to reproduce:

  1. Create a compat.h:
#pragma once

#if !__has_include(<optional>)

... use boost here...

#else

#include <optional>
namespace compat {
using std::optional;
}

#endif
  1. Create a test.cc:
#include "compat.h"

int main() {
  compat::optional<int> o;
}
  1. Run IWYU on this:
$ include-what-you-use -std=c++2a test.cc

Expected result: IWYU says there is nothing to do.

Actual result:

test.cc should add these lines:
#include <optional>  // for optional

test.cc should remove these lines:
- #include "compat.h"  // lines 1-1

The full include-list for test.cc:
#include <optional>  // for optional
---

But if I do what it says, I get:

test.cc:4:3: error: use of undeclared identifier 'compat'
  compat::optional<int> o;
  ^

Note that the problem is there even without the boost ifdef, I left it there from the original code to give you an idea why would anyone do using std::optional; in a namespace.

Version:

$ include-what-you-use --version
include-what-you-use 0.14 (git:d90fe9d) based on clang version 10.0.0 (git://github.com/llvm/llvm-project a3f896481329f64aac845e03cfda8f1154ce6079)

i.e. this is meant to be ~latest iwyu master vs llvm-project.git master.

As usual, if there are code pointers on what should be fixed here, I'm not against attempting to fix this myself, but I'm unsure where to start. :-)

Also, feel free to rename the issue, I'm just guessing what may be the root cause here.

Thanks,

Miklos

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions