Clang API parsing of the destructor

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

Clang API parsing of the destructor

Kamaljit Lall

I am using the clang API (version 3.1 - trunk 153913) to compile some very simple code as follows

class MyClass 
{ 
   ~
MyClass() ; 
 
}; 
 
MyClass::~MyClass() 
{ 
 
} 

 
int main() 

   
return 0

My problem is that I get the error message: test.cpp:20:10: error: destructor cannot have a return type MyClass::~MyClass()

If someone can point me to the right direction that would be great. It compiles fine if the destructor is defined inline to the class.

Note that I can also compile with clang++ fine: -bash-4.1$ clang++ test.cpp

So there must be a setting I'm missing in my clang API usage. Can anyone indicate what that might be. I've been searching all over for a missing option/configuration.

Here is my clang API usage:

// Include appropriate headers.  
int main() 

    clang::
DiagnosticOptions diagnosticOptions; 
    diagnosticOptions.
ShowColors=1
    diagnosticOptions.
ShowOptionNames=1
    clang::
TextDiagnosticPrinter *pTextDiagnosticPrinter = 
       
new clang::TextDiagnosticPrinter
           llvm::outs(), 
           diagnosticOptions); 
    llvm::
IntrusiveRefCntPtr<clang::DiagnosticIDs> pDiagIDs; 
    clang::
DiagnosticsEngine *pDiagnosticsEngine = 
       
new clang::DiagnosticsEngine(pDiagIDs, pTextDiagnosticPrinter); 
 
    clang::
LangOptions languageOptions; 
    languageOptions.
GNUMode = 1
    languageOptions.
CXXExceptions = 1
    languageOptions.RTTI =
1
    languageOptions.
Bool = 1
    languageOptions.
CPlusPlus = 1
    clang::
FileSystemOptions fileSystemOptions; 
    clang::
FileManager fileManager(fileSystemOptions); 
 
    clang::
SourceManager sourceManager( 
      *pDiagnosticsEngine, 
      fileManager); 
 
 
    clang::
TargetOptions targetOptions; 
     targetOptions.
Triple = "x86_64-unknown-linux-gnu"
    targetOptions.CPU =
"x86-64"
 
    clang::
TargetInfo *pTargetInfo = 
    clang::
TargetInfo::CreateTargetInfo
        *pDiagnosticsEngine, 

 


_______________________________________________
LLVM Developers mailing list
[hidden email]         http://llvm.cs.uiuc.edu
http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev
Reply | Threaded
Open this post in threaded view
|

Re: Clang API parsing of the destructor

Richard Smith-33
On Fri, Sep 21, 2012 at 12:22 PM, Kamaljit Lall <[hidden email]> wrote:

I am using the clang API (version 3.1 - trunk 153913) to compile some very simple code as follows

class MyClass 
{ 
   ~
MyClass() ; 
 
}; 
 
MyClass::~MyClass() 
{ 
 
} 

 
int main() 

   
return 0

My problem is that I get the error message: test.cpp:20:10: error: destructor cannot have a return type MyClass::~MyClass()

If someone can point me to the right direction that would be great. It compiles fine if the destructor is defined inline to the class.

Note that I can also compile with clang++ fine: -bash-4.1$ clang++ test.cpp

So there must be a setting I'm missing in my clang API usage. Can anyone indicate what that might be. I've been searching all over for a missing option/configuration.

Here is my clang API usage:

// Include appropriate headers.  
int main() 

    clang::
DiagnosticOptions diagnosticOptions; 
    diagnosticOptions.
ShowColors=1
    diagnosticOptions.
ShowOptionNames=1
    clang::
TextDiagnosticPrinter *pTextDiagnosticPrinter = 
       
new clang::TextDiagnosticPrinter
           llvm::outs(), 
           diagnosticOptions); 
    llvm::
IntrusiveRefCntPtr<clang::DiagnosticIDs> pDiagIDs; 
    clang::
DiagnosticsEngine *pDiagnosticsEngine = 
       
new clang::DiagnosticsEngine(pDiagIDs, pTextDiagnosticPrinter); 
 
    clang::
LangOptions languageOptions; 
    languageOptions.
GNUMode = 1
    languageOptions.
CXXExceptions = 1
    languageOptions.RTTI =
1
    languageOptions.
Bool = 1
    languageOptions.
CPlusPlus = 1


Don't do this, use CompilerInvocation::setLangDefaults. Your problem is probably that ImplicitInt is enabled (but you're likely to have other LangOptions wrong too, and this code may break next time we add one).
 

    clang::FileSystemOptions fileSystemOptions; 
    clang::
FileManager fileManager(fileSystemOptions); 
 
    clang::
SourceManager sourceManager( 
      *pDiagnosticsEngine, 
      fileManager); 
 
 
    clang::
TargetOptions targetOptions; 
     targetOptions.
Triple = "x86_64-unknown-linux-gnu"
    targetOptions.CPU =
"x86-64"
 
    clang::
TargetInfo *pTargetInfo = 
    clang::
TargetInfo::CreateTargetInfo
        *pDiagnosticsEngine, 

 


_______________________________________________
LLVM Developers mailing list
[hidden email]         http://llvm.cs.uiuc.edu
http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev



_______________________________________________
LLVM Developers mailing list
[hidden email]         http://llvm.cs.uiuc.edu
http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev
Reply | Threaded
Open this post in threaded view
|

Re: Clang API parsing of the destructor

Kamaljit Lall

Ok, thanks for that tip, that works.

 

Kam

 

 

From: [hidden email] [mailto:[hidden email]] On Behalf Of Richard Smith
Sent: Friday, September 21, 2012 4:45 PM
To: Kamaljit Lall
Cc: [hidden email]
Subject: Re: [LLVMdev] Clang API parsing of the destructor

 

On Fri, Sep 21, 2012 at 12:22 PM, Kamaljit Lall <[hidden email]> wrote:

I am using the clang API (version 3.1 - trunk 153913) to compile some very simple code as follows

class MyClass 

   ~MyClass() ; 
 
}; 
 
MyClass::~MyClass() 

 

 
int main() 

   return 0

My problem is that I get the error message: test.cpp:20:10: error: destructor cannot have a return type MyClass::~MyClass()

If someone can point me to the right direction that would be great. It compiles fine if the destructor is defined inline to the class.

Note that I can also compile with clang++ fine: -bash-4.1$ clang++ test.cpp

So there must be a setting I'm missing in my clang API usage. Can anyone indicate what that might be. I've been searching all over for a missing option/configuration.

Here is my clang API usage:

// Include appropriate headers.  
int main() 

    clang::DiagnosticOptions diagnosticOptions; 
    diagnosticOptions.ShowColors=1
    diagnosticOptions.ShowOptionNames=1
    clang::TextDiagnosticPrinter *pTextDiagnosticPrinter = 
       new clang::TextDiagnosticPrinter
           llvm::outs(), 
           diagnosticOptions); 
    llvm::IntrusiveRefCntPtr<clang::DiagnosticIDs> pDiagIDs; 
    clang::DiagnosticsEngine *pDiagnosticsEngine = 
       new clang::DiagnosticsEngine(pDiagIDs, pTextDiagnosticPrinter); 
 
    clang::LangOptions languageOptions; 
    languageOptions.GNUMode = 1
    languageOptions.CXXExceptions = 1
    languageOptions.RTTI = 1
    languageOptions.Bool = 1
    languageOptions.CPlusPlus = 1

 

Don't do this, use CompilerInvocation::setLangDefaults. Your problem is probably that ImplicitInt is enabled (but you're likely to have other LangOptions wrong too, and this code may break next time we add one).

 

    clang::FileSystemOptions fileSystemOptions; 
    clang::FileManager fileManager(fileSystemOptions); 
 
    clang::SourceManager sourceManager( 
      *pDiagnosticsEngine, 
      fileManager); 
 
 
    clang::TargetOptions targetOptions; 
     targetOptions.Triple = "x86_64-unknown-linux-gnu"
    targetOptions.CPU = "x86-64"
 
    clang::TargetInfo *pTargetInfo = 
    clang::TargetInfo::CreateTargetInfo
        *pDiagnosticsEngine, 

 


_______________________________________________
LLVM Developers mailing list
[hidden email]         http://llvm.cs.uiuc.edu
http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev

 


_______________________________________________
LLVM Developers mailing list
[hidden email]         http://llvm.cs.uiuc.edu
http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev