clang  14.0.0git
Public Types | Public Member Functions | Friends | List of all members
clang::Sema::SemaDiagnosticBuilder Class Reference

A generic diagnostic builder for errors which may or may not be deferred. More...

#include "clang/Sema/Sema.h"

Public Types

enum  Kind { K_Nop, K_Immediate, K_ImmediateWithCallStack, K_Deferred }
 

Public Member Functions

 SemaDiagnosticBuilder (Kind K, SourceLocation Loc, unsigned DiagID, FunctionDecl *Fn, Sema &S)
 
 SemaDiagnosticBuilder (SemaDiagnosticBuilder &&D)
 
 SemaDiagnosticBuilder (const SemaDiagnosticBuilder &)=default
 
 ~SemaDiagnosticBuilder ()
 
bool isImmediate () const
 
 operator bool () const
 Convertible to bool: True if we immediately emitted an error, false if we didn't emit an error or we created a deferred error. More...
 
template<typename T , typename = typename std::enable_if< !std::is_lvalue_reference<T>::value>::type>
const SemaDiagnosticBuilderoperator<< (T &&V) const
 
void AddFixItHint (const FixItHint &Hint) const
 
 operator ExprResult () const
 
 operator StmtResult () const
 
 operator TypeResult () const
 
 operator DeclResult () const
 
 operator MemInitResult () const
 

Friends

template<typename T >
const friend SemaDiagnosticBuilderoperator<< (const SemaDiagnosticBuilder &Diag, const T &Value)
 
const friend SemaDiagnosticBuilderoperator<< (const SemaDiagnosticBuilder &Diag, const PartialDiagnostic &PD)
 
ExprResult ExprError (const SemaDiagnosticBuilder &)
 
StmtResult StmtError (const SemaDiagnosticBuilder &)
 

Detailed Description

A generic diagnostic builder for errors which may or may not be deferred.

In CUDA, there exist constructs (e.g. variable-length arrays, try/catch) which are not allowed to appear inside device functions and are allowed to appear in host device functions only if the host+device function is never codegen'ed.

To handle this, we use the notion of "deferred diagnostics", where we attach a diagnostic to a FunctionDecl that's emitted iff it's codegen'ed.

This class lets you emit either a regular diagnostic, a deferred diagnostic, or no diagnostic at all, according to an argument you pass to its constructor, thus simplifying the process of creating these "maybe deferred" diagnostics.

Definition at line 1682 of file Sema.h.

Member Enumeration Documentation

◆ Kind

Enumerator
K_Nop 

Emit no diagnostics.

K_Immediate 

Emit the diagnostic immediately (i.e., behave like Sema::Diag()).

K_ImmediateWithCallStack 

Emit the diagnostic immediately, and, if it's a warning or error, also emit a call stack showing how this function can be reached by an a priori known-emitted function.

K_Deferred 

Create a deferred diagnostic, which is emitted only if the function it's attached to is codegen'ed.

Also emit a call stack as with K_ImmediateWithCallStack.

Definition at line 1684 of file Sema.h.

Constructor & Destructor Documentation

◆ SemaDiagnosticBuilder() [1/3]

Sema::SemaDiagnosticBuilder::SemaDiagnosticBuilder ( Kind  K,
SourceLocation  Loc,
unsigned  DiagID,
FunctionDecl Fn,
Sema S 
)

Definition at line 1770 of file Sema.cpp.

◆ SemaDiagnosticBuilder() [2/3]

Sema::SemaDiagnosticBuilder::SemaDiagnosticBuilder ( SemaDiagnosticBuilder &&  D)

Definition at line 1792 of file Sema.cpp.

◆ SemaDiagnosticBuilder() [3/3]

clang::Sema::SemaDiagnosticBuilder::SemaDiagnosticBuilder ( const SemaDiagnosticBuilder )
default

◆ ~SemaDiagnosticBuilder()

Sema::SemaDiagnosticBuilder::~SemaDiagnosticBuilder ( )

Definition at line 1802 of file Sema.cpp.

Member Function Documentation

◆ AddFixItHint()

void clang::Sema::SemaDiagnosticBuilder::AddFixItHint ( const FixItHint Hint) const
inline

Definition at line 1752 of file Sema.h.

References clang::Sema::DeviceDeferredDiags.

◆ isImmediate()

bool clang::Sema::SemaDiagnosticBuilder::isImmediate ( ) const
inline

Definition at line 1705 of file Sema.h.

Referenced by clang::Sema::Diag(), and operator bool().

◆ operator bool()

clang::Sema::SemaDiagnosticBuilder::operator bool ( ) const
inline

Convertible to bool: True if we immediately emitted an error, false if we didn't emit an error or we created a deferred error.

Example usage:

if (SemaDiagnosticBuilder(...) << foo << bar) return ExprError();

But see CUDADiagIfDeviceCode() and CUDADiagIfHostCode() – you probably want to use these instead of creating a SemaDiagnosticBuilder yourself.

Definition at line 1717 of file Sema.h.

References isImmediate().

◆ operator DeclResult()

clang::Sema::SemaDiagnosticBuilder::operator DeclResult ( ) const
inline

Definition at line 1768 of file Sema.h.

◆ operator ExprResult()

clang::Sema::SemaDiagnosticBuilder::operator ExprResult ( ) const
inline

Definition at line 1765 of file Sema.h.

References ExprError.

◆ operator MemInitResult()

clang::Sema::SemaDiagnosticBuilder::operator MemInitResult ( ) const
inline

Definition at line 1769 of file Sema.h.

◆ operator StmtResult()

clang::Sema::SemaDiagnosticBuilder::operator StmtResult ( ) const
inline

Definition at line 1766 of file Sema.h.

References StmtError.

◆ operator TypeResult()

clang::Sema::SemaDiagnosticBuilder::operator TypeResult ( ) const
inline

Definition at line 1767 of file Sema.h.

References clang::TypeError().

◆ operator<<()

template<typename T , typename = typename std::enable_if< !std::is_lvalue_reference<T>::value>::type>
const SemaDiagnosticBuilder& clang::Sema::SemaDiagnosticBuilder::operator<< ( T &&  V) const
inline

Definition at line 1735 of file Sema.h.

References clang::Sema::DeviceDeferredDiags, and V.

Friends And Related Function Documentation

◆ ExprError

ExprResult ExprError ( const SemaDiagnosticBuilder )
friend

Definition at line 1759 of file Sema.h.

Referenced by operator ExprResult().

◆ operator<< [1/2]

const friend SemaDiagnosticBuilder& operator<< ( const SemaDiagnosticBuilder Diag,
const PartialDiagnostic PD 
)
friend

Definition at line 1744 of file Sema.h.

◆ operator<< [2/2]

template<typename T >
const friend SemaDiagnosticBuilder& operator<< ( const SemaDiagnosticBuilder Diag,
const T &  Value 
)
friend

Definition at line 1721 of file Sema.h.

◆ StmtError

StmtResult StmtError ( const SemaDiagnosticBuilder )
friend

Definition at line 1762 of file Sema.h.

Referenced by operator StmtResult().


The documentation for this class was generated from the following files: