diff --git a/include/gauxc/shell.hpp b/include/gauxc/shell.hpp index 7f27170c..32cb50e6 100644 --- a/include/gauxc/shell.hpp +++ b/include/gauxc/shell.hpp @@ -14,6 +14,8 @@ #include #include #include +#include +#include #include #include #include @@ -138,6 +140,12 @@ class alignas(256) Shell { alpha_( alpha ), coeff_( coeff ), O_( O ), nprim_( nprim.get() ), l_( l.get() ), pure_( pure.get() ) { + if(nprim_ > static_cast(detail::shell_nprim_max)) { + std::ostringstream oss; + oss << "Shell has too many primitives! expected <= " << detail::shell_nprim_max << " actual value " << nprim_ << "!\n"; + throw std::out_of_range(oss.str()); + } + if( _normalize ) normalize(); compute_shell_cutoff(); diff --git a/tests/basisset_test.cxx b/tests/basisset_test.cxx index 29565336..51fa3955 100644 --- a/tests/basisset_test.cxx +++ b/tests/basisset_test.cxx @@ -20,6 +20,8 @@ #include #include +#include +#include #include @@ -184,6 +186,25 @@ TEST_CASE("Shell", "[basisset]") { } + SECTION("Too Many Primitives") { + + const auto nprim = PrimSize(detail::shell_nprim_max + 1); + const prim_array alpha = {0.8}; + const prim_array coeff = {0.5}; + + try { + Shell sh( nprim, AngularMomentum(0), SphericalType(false), + alpha, coeff, center ); + FAIL( "Expected Shell construction to throw" ); + } catch( const std::out_of_range& ex ) { + const std::string message = ex.what(); + CHECK( message.find( "Shell has too many primitives!" ) != std::string::npos ); + CHECK( message.find( "expected <= 32" ) != std::string::npos ); + CHECK( message.find( "actual value 33" ) != std::string::npos ); + } + + } + }