Commit 3aafa30
authored
Fix parser expressions (#2682)
* Fix segmentation faults in amrex::Parser if a constant was not defined.
Without this fix, the following segments of code all seg-fault.
With this fix, each of them will throw an exception instead.
(If the setConstant lines are uncommented, the tests will pass with or without this fix.)
{
amrex::Print() << "Attempt 2+a" << std::endl;
amrex::Parser parser("2+a");
//parser.setConstant("a", (amrex::Real)3.0);
const auto parserExec = parser.compile<0>();
AMREX_ALWAYS_ASSERT(parserExec() == 5);
}
{
amrex::Print() << "Attempt 2-a" << std::endl;
amrex::Parser parser("2-a");
//parser.setConstant("a", (amrex::Real)3.0);
const auto parserExec = parser.compile<0>();
AMREX_ALWAYS_ASSERT(parserExec() == -1);
}
{
amrex::Print() << "Attempt 2*a" << std::endl;
amrex::Parser parser("2*a");
//parser.setConstant("a", (amrex::Real)3.0);
const auto parserExec = parser.compile<0>();
AMREX_ALWAYS_ASSERT(parserExec() == 6);
}
{
amrex::Print() << "Attempt 3/a" << std::endl;
amrex::Parser parser("3/a");
//parser.setConstant("a", (amrex::Real)3.0);
const auto parserExec = parser.compile<0>();
AMREX_ALWAYS_ASSERT(parserExec() == 1);
}
{
amrex::Print() << "Attempt -a" << std::endl;
amrex::Parser parser("-a");
//parser.setConstant("a", (amrex::Real)3.0);
const auto parserExec = parser.compile<0>();
AMREX_ALWAYS_ASSERT(parserExec() == -3);
}1 parent 8b691cb commit 3aafa30
1 file changed
+20
-0
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
546 | 546 | | |
547 | 547 | | |
548 | 548 | | |
| 549 | + | |
| 550 | + | |
| 551 | + | |
| 552 | + | |
549 | 553 | | |
550 | 554 | | |
551 | 555 | | |
| |||
564 | 568 | | |
565 | 569 | | |
566 | 570 | | |
| 571 | + | |
| 572 | + | |
| 573 | + | |
| 574 | + | |
567 | 575 | | |
568 | 576 | | |
569 | 577 | | |
| |||
582 | 590 | | |
583 | 591 | | |
584 | 592 | | |
| 593 | + | |
| 594 | + | |
| 595 | + | |
| 596 | + | |
585 | 597 | | |
586 | 598 | | |
587 | 599 | | |
| |||
600 | 612 | | |
601 | 613 | | |
602 | 614 | | |
| 615 | + | |
| 616 | + | |
| 617 | + | |
| 618 | + | |
603 | 619 | | |
604 | 620 | | |
605 | 621 | | |
| |||
710 | 726 | | |
711 | 727 | | |
712 | 728 | | |
| 729 | + | |
| 730 | + | |
| 731 | + | |
| 732 | + | |
713 | 733 | | |
714 | 734 | | |
715 | 735 | | |
| |||
0 commit comments