2017-06-04 15 views
5

निम्नलिखित समस्या पर विचार करें जो -std=c++14 का उपयोग कर क्लैंग 3.8 पर सफलतापूर्वक संकलित करता है।static_assert से संबंधित क्लैंग संकलन त्रुटि और बढ़ावा :: हाना

#include <boost/hana.hpp> 

namespace hana = boost::hana; 

int main() { 
    constexpr auto indices = hana::range<unsigned, 0, 3>(); 
    hana::for_each(indices, [&](auto i) { 
     hana::for_each(indices, [&](auto j) { 
      constexpr bool test = (i == (j == i ? j : i)); 
      static_assert(test, "error"); 
     }); 
    }); 
} 

परीक्षण काफी गैर-संवेदी है लेकिन यह बात नहीं है। अब एक वैकल्पिक संस्करण जहां परीक्षण सीधे static_assert अंदर डाला जाता है पर विचार करें:

#include <boost/hana.hpp> 

namespace hana = boost::hana; 

int main() { 
    constexpr auto indices = hana::range<unsigned, 0, 3>(); 
    hana::for_each(indices, [&](auto i) { 
     hana::for_each(indices, [&](auto j) { 
      static_assert((i == (j == i ? j : i)), "error"); 
     }); 
    }); 
} 

अब मैं संकलन त्रुटियों की एक गुच्छा मिलता है, कह रही है

error: reference to local variable i declared in enclosing lambda expression

प्रश्न: विफल दूसरे संस्करण का कारण बनता है?

संपादित करें: क्या यह एक कंपाइलर बग हो सकता है? मैं पता चला है कि जब static_assert से पहले i तक पहुँचने, सब कुछ फिर से संकलित:

#include <boost/hana.hpp> 

namespace hana = boost::hana; 

int main() { 
    constexpr auto indices = hana::range<unsigned, 0, 3>(); 
    hana::for_each(indices, [&](auto i) { 
     hana::for_each(indices, [&](auto j) { 
      constexpr auto a = i; 
      static_assert((i == (j == i ? j : i)), "error"); 
     }); 
    }); 
} 

अद्यतन: समान व्यवहार बजना 4.0 और वर्तमान विकास शाखा 5.0 पर पुनः प्रस्तुत किया जा सकता है।

अद्यतन 2: https://bugs.llvm.org/show_bug.cgi?id=33318: @LouisDionne ने सुझाव दिया है, मैं एक बग के रूप में इस दायर किया।

+0

@aschepler: क्षमा करें - मुझे आपकी बात नहीं मिलती है। क्या आप विस्तार से बात करेंगे? – LocalVolatility

+1

"यह" समान है https://stackoverflow.com/questions/43665610/why-is-this-nested-lambda-not-considered-constexpr –

+1

मैं _believe_ कि एक कंपाइलर बग है। मुझे लगता है कि आपकी सबसे अच्छी शर्त क्लैंग के खिलाफ एक बग फाइल करना है और देखें कि वहां पर जानकार लोग क्या सोचते हैं। –

उत्तर

संबंधित मुद्दे