1

Consider the following code.

namespace A::B::C::D::E {
    struct X { };
}

namespace B {
    using namespace A::B::C::D::E;
    // or, using A::B::C::D::E::X;
    // or, using X = A::B::C::D::E::X;
}

Let's say I use B::X incorrectly in some way and get an error. That error, in clang at least, will look something like

error: ... for type A::B::C::D::E::X.

I'd much rather have the error stated for B::X.

Is there a way to configure clang error messages to use the locations of using declarations, instead of the aliased entity?

curiousguy
  • 8,038
  • 2
  • 40
  • 58
Anthony
  • 1,015
  • 8
  • 22

1 Answers1

0

I think it is good that the compiler uses A::B::C::D::E::X because otherwise it could be ambiguous. Like in the following example:

namespace A::B::C::D::E {
    struct X {
      int y;
    };
}

namespace B {
  using namespace A::B::C::D::E;

  void foo() {
    X aa;
    B::X bb;
    aa.y = 0;
  }

  struct X {
    int z;
  };

  void bar() {
    X aa;
    B::X bb;
    aa.y = 0;
  }

}

int main() {
  return 0;
}

There can be a struct X declared in the B namespace, and then that is B::X and it is necessary to call the other one A::B::C::D::E::X since otherwise they could not be distinguished.

Elias
  • 913
  • 6
  • 22
  • That is true, but I think clang is capable enough to recognize the difference in our cases. Namely, the use of a *using directive* or *using declaration*, as opposed to type declarations and/or definitions. I don't think the compiler how to treat our cases the same. – Anthony Apr 15 '19 at 10:49