2013-09-07 24 views
11

following code ile yapıcı başlatma listesindeki tek tip başlatma kullanamazsınız:gcc ile derleme değil try/catch

struct test { 
    int x; 
    test() try : x{123} { 
    } 
    catch (...) { 
    } 
}; 

int main() {} 

Hataları: x(123) için x{123} yardımcı olur değiştirilmesi

prog.cpp:3:25: error: expected unqualified-id before ‘{’ token 
    test() try : x{123} { 
         ^
prog.cpp:5:5: error: expected unqualified-id before ‘catch’ 
    catch (...) { 
    ^
prog.cpp: In constructor ‘test::test()’: 
prog.cpp:3:23: error: expected ‘{’ at end of input 
    test() try : x{123} { 
        ^
prog.cpp:3:23: error: expected ‘catch’ at end of input 
prog.cpp:3:23: error: expected ‘(’ at end of input 
prog.cpp:3:23: error: expected type-specifier at end of input 
prog.cpp:3:23: error: expected ‘)’ at end of input 
prog.cpp:3:23: error: expected ‘{’ at end of input 

. Bu şekilde çalışmalı mıyım? (Aynı catch GCC 4.8 sahiptir yanlış, ama GCC 4.9 düzgün kolları -

Bu standardın gramer göre geçerlidir
+2

Clang [derler] (http://coliru.stacked-crooked.com/a/0e8921393e3a52f1) hatasız – Praetorian

+3

Parantez ve C++ 11 ile ilgili her şey çok Tamamen eksik olması muhtemel Bir süredir derleyicilerde düzeltilmiş köşe ... –

+3

@KerrekSB Başlangıçta bir hata olduğunu düşündüm, fakat Stroustrup'un kitabında kurucularda üniforma başlatma işlemini kullanıyor, çünkü bir deneme/yakalama olduğu zamanlar hariç, bu beni biraz şaşırttı. – catscradle

cevap

1

(parantez için [gram.special] görmek ve [gram.except] try için. Daha önce bildirildiği gibi diğer derleyicileri yapın.

BS'nin bu sözdizimini kitabında neden kullanması konusunda hiçbir fikrim yok. Belki de onun örneklerini derlediğinde bu sözdizimini destekleyen herhangi bir derleyicisinin olmaması nedeniyle eğer haklılarsa (eğer yaptıysa)?