   templates and using directive
  Hi,I'm having some difficulties getting the following sample parsed by some compiler/parser and am wondering whether the syntax is correct according to the C++ standard.The following code snippet represents the issue:template<class T> class Foo : public T{typename T::iterator find();using T::find;};template<class T> typename T::iterator Foo<T>::find(){ return T::find();}class Bar {public:typedef int iterator;iterator find() { return 5; }};void main(){}The error message I'm getting from the parser (in this case PC Lint) is:Quote:Issue 1051: (Error -- Symbol 'find' is both a function and a variable)The interesting thing is that when I either remove "using T::find;" or replace "typename T::iterator find();" with "int find();" the parser accepts the construct.Now I'm wondering whether I've used some non-100% conformant C++ syntax or whether there's really a flaw in the 3rd party tool.   
Quote:template<class T> class Foo : public T{typename T::iterator find();};This is semantic ambiguity, the compiler cannot tell whether find is declaration of function, or whether it's declaring a variable using no-arg constructor.int main() {  int i();}Can be function i returning an int, can be variable i no-arg constructed - compiler can't tell.Strangely enough:void main()is an error, should return an int.Cause for this is C++ and its context-dependent grammar. While almost never an issue for compilers, it can cause compile errors, but shouldn't in above context. The ambiguity likely exists since at that point, templates haven't been instantiated yet, so function definition of find<T> doesn't exist.Quote:in this case PC Lint)PCLint is generally right, but getting rid of all the errors it reports is often not viable.PS: And if I'm right on the above, then it's slowly time for me to lay off C++. This stuff is getting deep...   ;  Please correct me if I'm wrong about anything here --- I just read through the standard and hence think there are some contradictary statements to urs. I'm refering to "The annotated C++ reference manual" from 1990:Quote:This is semantic ambiguity, the compiler cannot tell whether find is declaration of function, or whether it's declaring a variable using no-arg constructor.[9.2 p171]: "Note that a member-declarator cannot contain an initializer."If I take that into account I'd argue that even if there is an ambiguity here for non-context sensitive lexers, it should be properly parsed by the parser, simply because of the parantheses after the identifier "find" which by the standard cannot be a variable using the "no-arg constructor" (or the "Explicit type conversion" as it is called in the standard --- unless I mixed those here).Quote:Can be function i returning an int, can be variable i no-arg constructed - compiler can't tell.[6.8 p94]: "A slight different ambiguity between expression-statements and declarations is resolved by requiring a type-name for function declarations within a block."Therefore must not "int i()" be considered a function declaration in ur given example and hence the compiler must be possible to resolve the ambiguity again?Quote:The ambiguity likely exists since at that point, templates haven't been instantiated yet, so function definition of find<T> doesn't exist.That would make sense, if PCLint wouldn't omit the error message, if I use either of these definitions for class Foo:// example 1template<class T> class Foo : public T{void find(); // works fine nowusing T::find;};// example 2template<class T> class Foo : public T{typename T::iterator find(); // works fine now};Or did I miss ur point somewhere?Just as a sidenote:Quote:PCLint is generally right, but getting rid of all the errors it reports is often not viable.I agree that especially the past versions of PCLint (version 8.x) were really a PITA to get to work with larger production code (especially when used for non-embedded projects). However version 9.0 introduced proper support for PCHs and also made some significant improvements with MS VS compiler environments so that with our current code I'm down to just a few "errors".I'm just talking about errors here, because they leave PCLint with not recognizing the correct code structure and lead to undeserved warnings later in the code just because PC Lint doesn't have the knowledge of Foo being an enum or somesuch.So if u gave it a try in the past, u might wanna take another look at the current version, which really made it a lot more useable.   ;Quote:Original post by Luke1410I'm refering to "The annotated C++ reference manual" from 1990:I'd prefer another document which is 20 years younger :)   ;  You are of course right in that my reference is a little outdated. :-)However, I wouldn't use the C++0x draft u referenced simply because our projects still rely on C++98/C++03 (aka VS 2005/2008 w/o TR1). But in order to update my statements a bit, I'll refer to the C++03 standard:Section 9.2 changed a bit, but the argument still stands:paragraph 4: "A member-declarator can contain a constant-initializer only if it declares a static member (9.4) of integral or enumeration type, see 9.4.2."However, concerning the recited section 6.8: That paragraph has been removed and I couldn't easily spot any corresponding reference in the C++03 standard. So feel free to ignore that. :-)Since the both of you didn't really spot an obvious error in my code sample, I think I'll go forward and send out a support request to gimpel to see what they make of it.Thanks for the discussion.   ;  Just to complete this thread:PC Lint's latest beta (version 9.0d3) no longer raises the reported error. Hence I suspect that it indeed was a bug in the parser/compiler and the syntax complies to the C++ standard.Again, thanks for ur replies to this thread.   