Home | History | Annotate | Line # | Download | only in gdb.compile
      1 # Copyright 2015-2024 Free Software Foundation, Inc.
      2 
      3 # This program is free software; you can redistribute it and/or modify
      4 # it under the terms of the GNU General Public License as published by
      5 # the Free Software Foundation; either version 3 of the License, or
      6 # (at your option) any later version.
      7 #
      8 # This program is distributed in the hope that it will be useful,
      9 # but WITHOUT ANY WARRANTY; without even the implied warranty of
     10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     11 # GNU General Public License for more details.
     12 #
     13 # You should have received a copy of the GNU General Public License
     14 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
     15 
     16 # Member tests for GDB's C++ compile feature.
     17 
     18 load_lib compile-support.exp
     19 
     20 standard_testfile .cc
     21 
     22 require allow_cplus_tests
     23 
     24 require is_c_compiler_gcc
     25 
     26 if {[prepare_for_testing $testfile $testfile $srcfile \
     27 	 {debug nowarnings c++}]} {
     28     return -1
     29 }
     30 
     31 if {![runto_main]} {
     32     return -1
     33 }
     34 
     35 gdb_breakpoint [gdb_get_line_number "break here" $srcfile]
     36 gdb_continue_to_breakpoint "testing location"
     37 
     38 if {[skip_compile_feature_untested "var = 0"]} {
     39     return -1
     40 }
     41 
     42 CompileExpression::new "var"
     43 CompileExpression::test "a.public_" 1
     44 CompileExpression::test "a.protected_" {(21|N::NB)}
     45 CompileExpression::test "a.private_" 3
     46 CompileExpression::test "A::s_public_" {(10|E_A)}
     47 CompileExpression::test "A::s_protected_" {(20|N::NA)}
     48 CompileExpression::test "A::s_private_" {(12|E_C)}
     49 CompileExpression::test "A::ATYPE i = 10; var = i;" 10 -explicit
     50 CompileExpression::test "get_values (a)" 125
     51 CompileExpression::test "myenum me = E_B; var = me;" 11 -explicit
     52 CompileExpression::test "A::s_protected_ = N::NB; var = A::s_protected_;" \
     53     21 -explicit
     54 CompileExpression::test "A::s_private_ = E_B; var = A::s_private_;" 11 -explicit
     55 CompileExpression::test "N::ANON_NE ae = N::ND; var = ae;" 23 -explicit
     56 CompileExpression::test {a.*pmi} 1
     57 CompileExpression::test {a.public_ = 2; var = a.*pmi; a.public_ = 1} 2 -explicit
     58 CompileExpression::test "g_e" {(42|AC)}
     59 
     60 # Test some compilation failures
     61 set failed {\r\nCompilation failed\.}
     62 gdb_test "compile code a.s_public_ = E_B" \
     63     ".*assignment of read-only variable 'A::s_public_'$failed"
     64 
     65 gdb_test "compile code get_values ()" \
     66     ".*too few arguments to function.*$failed"
     67 
     68 gdb_test "compile code ATYPE i;" \
     69     ".*.ATYPE. was not declared in this scope$failed"
     70 
     71 gdb_test "compile code N::ANON_NE nse = E_A" \
     72     ".*cannot convert.*$failed"
     73