Condividi tramite


Avviso C26814

La variabile const 'variable' può essere calcolata in fase di compilazione. Prendere in considerazione l'uso constexpr di (con.5)

Osservazioni:

Utilizzare constexpr per le costanti il cui valore è noto in fase di compilazione. (Con.5)

Nome dell'analisi del codice: USE_CONSTEXPR_RATHER_THAN_CONST

Esempio

const int foo = 1234;  // C26814 reported here.
constexpr int getMagicNumber()
{
    return 42;
}

void bar()
{
    const int myval = 3; // C26814 reported here
    const int magicNumber = getMagicNumber(); // C26814 reported here.
}

Vedi anche

Con.5 Usare constexpr per tutte le variabili che possono essere calcolate in fase di compilazione