Menu

#371 Parser getting confused with forward declaration

open
nobody
5
2012-09-26
2004-07-21
No

The cpp parser seems to get confused with forward
declarations. In wxWidgets some classes are (forward)
declared something like

class WX_DECLARE_DLLEXPORT wxMyCustomClass;

When the parser see this forward declaration, it
assumes wxMyCustomClass as a variable and when it tries
to parse the actual file that contains the
wxMyCustomClass declaration/definition, it ignores it
(since a variable name alerady exists). So the
code-completion feature doesnt work for the variables
that are instantiated from wxMyCustomClass.

work around :
The main reason for this problem is the forward
declaration is given in some file that resides in
\include\wx\ but the actual class definition is given
in \include\wx\MSW or the directory that corresponds to
the OS. If we make the \include\wx\MSW\ parsed first
then we wont have problem with the files available in
\include\wx\ .

Discussion

  • Nobody/Anonymous

    Logged In: NO

    What about such work around: variable of type class is not
    parsed if is not expanded to full declaration ( I mean there is
    no corresponding {} after that) Anyway foward declaration
    need full declaration later I'm I right so if this one not exists -
    there is a bug in program source)

    Bogusław Brandys
    brandys@o2.pl

     
  • Guru Kathiresan

    Guru Kathiresan - 2004-07-25

    Logged In: YES
    user_id=677339

    I think I havent made my case clearer. In the declaration

    class WX_DECLARE_DLLEXPORT wxMyCustomClass;

    wxMyCustomClass is parsed as a variable of
    WX_DECLARE_DLLEXPORT , but WX_DECLARE_DLLEXPORT is a kinda
    of dummy define. So the compiler will be smart enough to
    convert the above line as

    class wxMyCustomClass;

    which is a forward declaration that wont be seen by the
    naked eye.

    I guess in C++ , just like struct declaration, you can
    declare a class object variable like :

    class ClassName classObj;
    (just like struct)
    struct StructName structObj;

    so the parser assumes that the above defined line as a
    variable declaration. Also you have to note that the class
    does have a full declaration, which was ignored by the parser.

     

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.