int cp_unevaluated_operand;
int c_inhibit_evaluation_warnings;
int cp_noexcept_operand_;
+ bool has_cfun;
static local_state_t
save_and_clear ()
::c_inhibit_evaluation_warnings = 0;
s.cp_noexcept_operand_ = ::cp_noexcept_operand;
::cp_noexcept_operand = 0;
+ s.has_cfun = !!cfun;
+ if (s.has_cfun)
+ push_function_context ();
return s;
}
::cp_unevaluated_operand = this->cp_unevaluated_operand;
::c_inhibit_evaluation_warnings = this->c_inhibit_evaluation_warnings;
::cp_noexcept_operand = this->cp_noexcept_operand_;
+ if (this->has_cfun)
+ pop_function_context ();
}
};
else
{
gcc_assert (!processing_template_decl);
- push_function_context ();
local_state_stack.safe_push (local_state_t::save_and_clear ());
}
if (push_to_top)
pop_from_top_level ();
else
- {
- local_state_stack.pop ().restore ();
- pop_function_context ();
- }
+ local_state_stack.pop ().restore ();
}
/* Push into the scope of the namespace NS, even if it is deeply
--- /dev/null
+// PR c++/123354
+// { dg-do compile { target c++11 } }
+// ICE with static local var referenced in NSDMI of local class
+
+template<typename T>
+void foo() {
+ static constexpr int value = 42;
+ struct s1_t {
+ struct s2_t {
+ int dummy { 0 };
+ char* ptr { static_cast<char*>(::operator new(sizeof(value)))};
+ } s2;
+ } object;
+}
+
+int main() {
+ foo<void>();
+}