2016-07-15 297 views
7

Sto usando le seguenti opzioni nel mio file .clang-format:clang-formato: Allineare asterisco (*) della dichiarazione di puntatore con il nome della variabile

AlignConsecutiveDeclarations: true 
PointerAlignment: Right 

Il risultato corrente formattazione è il seguente:

char *   var1; 
SomeOtherType *var2; 
int   var3; 

Il risultato mi aspettavo sarebbe:

char   *var1; //note the changed position of * 
SomeOtherType *var2; 
int   var3; 

Come posso configurare clang-format per allineare l'asterisco (*) con il nome della variabile piuttosto che con il tipo quando sono utilizzando l'opzione AlignConsecutiveDeclarations?

risposta

7

PointerAlignment: Right non è ancora stato implementato.

Vedi https://github.com/llvm-mirror/clang/blob/release_39/lib/Format/WhitespaceManager.cpp#L327-L340

void WhitespaceManager::alignConsecutiveDeclarations() { 
    if (!Style.AlignConsecutiveDeclarations) 
    return; 

    // FIXME: Currently we don't handle properly the PointerAlignment: Right 
    // The * and & are not aligned and are left dangling. Something has to be done 
    // about it, but it raises the question of alignment of code like: 
    // const char* const* v1; 
    // float const* v2; 
    // SomeVeryLongType const& v3; 

    AlignTokens(Style, [](Change const &C) { return C.IsStartOfDeclName; }, 
       Changes); 
}