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

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

#include "clang/Sema/SemaBase.h"

Public Types

enum  Kind { K_Nop , K_Immediate , K_ImmediateWithCallStack , K_Deferred }
 
using DeferredDiagnosticsType = llvm::DenseMap< CanonicalDeclPtr< const FunctionDecl >, std::vector< PartialDiagnosticAt > >
 

Public Member Functions

 SemaDiagnosticBuilder (Kind K, SourceLocation Loc, unsigned DiagID, const FunctionDecl *Fn, Sema &S)
 
 SemaDiagnosticBuilder (SemaDiagnosticBuilder &&D)
 
 SemaDiagnosticBuilder (const SemaDiagnosticBuilder &)=default
 
SemaDiagnosticBuilderoperator= (const SemaDiagnosticBuilder &)=delete
 
SemaDiagnosticBuilderoperator= (SemaDiagnosticBuilder &&)=delete
 
 ~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.
 
template<typename T , typename = std::enable_if_t<!std::is_lvalue_reference<T>::value>>
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 SemaDiagnosticBuilderoperator<< (const SemaDiagnosticBuilder &Diag, const T &Value)
 
const 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 110 of file SemaBase.h.

Member Typedef Documentation

◆ DeferredDiagnosticsType

Definition at line 194 of file SemaBase.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 112 of file SemaBase.h.

Constructor & Destructor Documentation

◆ SemaDiagnosticBuilder() [1/3]

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

◆ SemaDiagnosticBuilder() [2/3]

clang::SemaBase::SemaDiagnosticBuilder::SemaDiagnosticBuilder ( SemaDiagnosticBuilder &&  D)

◆ SemaDiagnosticBuilder() [3/3]

clang::SemaBase::SemaDiagnosticBuilder::SemaDiagnosticBuilder ( const SemaDiagnosticBuilder )
default

◆ ~SemaDiagnosticBuilder()

clang::SemaBase::SemaDiagnosticBuilder::~SemaDiagnosticBuilder ( )

Member Function Documentation

◆ AddFixItHint()

void clang::SemaBase::SemaDiagnosticBuilder::AddFixItHint ( const FixItHint Hint) const

Definition at line 46 of file SemaBase.cpp.

◆ isImmediate()

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

Definition at line 139 of file SemaBase.h.

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

◆ operator bool()

clang::SemaBase::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 DiagIfDeviceCode() and DiagIfHostCode() – you probably want to use these instead of creating a SemaDiagnosticBuilder yourself.

Definition at line 151 of file SemaBase.h.

References isImmediate().

◆ operator DeclResult()

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

Definition at line 191 of file SemaBase.h.

◆ operator ExprResult()

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

Definition at line 188 of file SemaBase.h.

References ExprError.

◆ operator MemInitResult()

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

Definition at line 192 of file SemaBase.h.

◆ operator StmtResult()

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

Definition at line 189 of file SemaBase.h.

References StmtError.

◆ operator TypeResult()

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

Definition at line 190 of file SemaBase.h.

References clang::TypeError().

◆ operator<<()

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

Definition at line 169 of file SemaBase.h.

References V.

◆ operator=() [1/2]

SemaDiagnosticBuilder & clang::SemaBase::SemaDiagnosticBuilder::operator= ( const SemaDiagnosticBuilder )
delete

◆ operator=() [2/2]

SemaDiagnosticBuilder & clang::SemaBase::SemaDiagnosticBuilder::operator= ( SemaDiagnosticBuilder &&  )
delete

Friends And Related Function Documentation

◆ ExprError

ExprResult ExprError ( const SemaDiagnosticBuilder )
friend

Definition at line 182 of file SemaBase.h.

Referenced by operator ExprResult().

◆ operator<< [1/2]

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

Definition at line 36 of file SemaBase.cpp.

◆ operator<< [2/2]

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

Definition at line 154 of file SemaBase.h.

◆ StmtError

StmtResult StmtError ( const SemaDiagnosticBuilder )
friend

Definition at line 185 of file SemaBase.h.

Referenced by operator StmtResult().


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