OrangeC icon indicating copy to clipboard operation
OrangeC copied to clipboard

OCC getting unexpected end of file on valid file

Open chuggafan opened this issue 4 years ago • 3 comments

Found this while attempting to write example code for the issue I was originally going to make to succeed #574, I don't know why, but in parsing the struct body there's an "unexpected end of file" since at some point the lexer becomes a nullptr.

Investigating why shortly, however, without further ado, the source code causing the issues:

#define _LIBCPP_CONSTEXPR constexpr
template <class _Tp, _Tp __v>
struct integral_constant
{
  static _LIBCPP_CONSTEXPR const _Tp      value = __v;
  typedef _Tp               value_type;
  typedef integral_constant type;
  
  _LIBCPP_CONSTEXPR operator value_type() const _NOEXCEPT {return value;}
  constexpr value_type operator ()() const _NOEXCEPT {return value;}
};

template <class _Tp, _Tp __v>
_LIBCPP_CONSTEXPR const _Tp integral_constant<_Tp, __v>::value;

#define _LIBCPP_BOOL_CONSTANT(__b) integral_constant<bool,(__b)>

typedef _LIBCPP_BOOL_CONSTANT(true)  true_type;
typedef _LIBCPP_BOOL_CONSTANT(false) false_type;
template <class _Tp, class... _Args>
struct is_nothrow_constructible
    : public integral_constant<bool, __is_nothrow_constructible(_Tp, _Args...)> {};
template <class _Tp> struct is_nothrow_default_constructible
    : public is_nothrow_constructible<_Tp>
    {};

typedef void* __libcpp_mutex_t;
#define _LIBCPP_MUTEX_INITIALIZER 0
#define _NOEXCEPT noexcept
class mutex
{
    __libcpp_mutex_t __m_ = _LIBCPP_MUTEX_INITIALIZER;

public:
    
    mutex() = default;

    mutex(const mutex&) = delete;
    mutex& operator=(const mutex&) = delete;

    ~mutex() = default;

    void lock();
    bool try_lock() _NOEXCEPT;
    void unlock() _NOEXCEPT;

    typedef __libcpp_mutex_t* native_handle_type;
    native_handle_type native_handle() {return &__m_;}
};

static_assert(is_nothrow_default_constructible<mutex>::value,
              "the default constructor for std::mutex must be nothrow");

int main()
{
    return 0;
}

chuggafan avatar May 28 '21 13:05 chuggafan

Found the issue: that _NOEXCEPT define is too far down for the integral_constant struct, causing it to bug out and crash with the error "unexpected end of file".

Fun times.

chuggafan avatar May 28 '21 13:05 chuggafan

yeah maybe we can improve this. I'm going to leave it for the moment though...

LADSoft avatar May 28 '21 19:05 LADSoft

Can you attach that to an appropriate milestone?

GitMensch avatar Jul 28 '21 09:07 GitMensch