@@ -1775,6 +1775,197 @@ int main()
1775
1775
}
1776
1776
EOF
1777
1777
1778
+ # Category: Const Qualifiers
1779
+ begin_category " Const Qualifiers" " Testing const qualifier support for variables and parameters"
1780
+
1781
+ # Test 1: Basic const local variable
1782
+ try_ 42 << EOF
1783
+ int main() {
1784
+ const int x = 42;
1785
+ return x;
1786
+ }
1787
+ EOF
1788
+
1789
+ # Test 2: Const global variable
1790
+ try_ 100 << EOF
1791
+ const int global_const = 100;
1792
+ int main() {
1793
+ return global_const;
1794
+ }
1795
+ EOF
1796
+
1797
+ # Test 3: Multiple const variables
1798
+ try_ 30 << EOF
1799
+ int main() {
1800
+ const int a = 10;
1801
+ const int b = 20;
1802
+ return a + b;
1803
+ }
1804
+ EOF
1805
+
1806
+ # Test 4: Const parameter in function
1807
+ try_ 15 << EOF
1808
+ int add_five(const int x) {
1809
+ return x + 5;
1810
+ }
1811
+ int main() {
1812
+ return add_five(10);
1813
+ }
1814
+ EOF
1815
+
1816
+ # Test 5: Const pointer value (simplified)
1817
+ try_ 25 << EOF
1818
+ int main() {
1819
+ const int value = 25;
1820
+ const int *ptr = &value;
1821
+ return *ptr;
1822
+ }
1823
+ EOF
1824
+
1825
+ # Test 6: Non-const pointer to const data
1826
+ try_ 35 << EOF
1827
+ int main() {
1828
+ const int value = 35;
1829
+ int *ptr = &value;
1830
+ return *ptr;
1831
+ }
1832
+ EOF
1833
+
1834
+ # Test 7: Const in arithmetic expressions
1835
+ try_ 60 << EOF
1836
+ int main() {
1837
+ const int x = 20;
1838
+ const int y = 30;
1839
+ const int z = 10;
1840
+ return x + y + z;
1841
+ }
1842
+ EOF
1843
+
1844
+ # Test 8: Const with initialization from expression
1845
+ try_ 50 << EOF
1846
+ int main() {
1847
+ int a = 10;
1848
+ const int b = a * 5;
1849
+ return b;
1850
+ }
1851
+ EOF
1852
+
1853
+ # Test 9: Function returning through const variable
1854
+ try_ 77 << EOF
1855
+ int compute() {
1856
+ const int result = 77;
1857
+ return result;
1858
+ }
1859
+ int main() {
1860
+ return compute();
1861
+ }
1862
+ EOF
1863
+
1864
+ # Test 10: Const array element access
1865
+ try_ 30 << EOF
1866
+ int main() {
1867
+ const int arr[3] = {10, 20, 30};
1868
+ return arr[2];
1869
+ }
1870
+ EOF
1871
+
1872
+ # Test 11: Mixed const and non-const
1873
+ try_ 45 << EOF
1874
+ int main() {
1875
+ const int x = 15;
1876
+ int y = 20;
1877
+ const int z = 10;
1878
+ return x + y + z;
1879
+ }
1880
+ EOF
1881
+
1882
+ # Test 12: Const with conditional
1883
+ try_ 40 << EOF
1884
+ int main() {
1885
+ const int x = 40;
1886
+ const int y = 50;
1887
+ return (x < y) ? x : y;
1888
+ }
1889
+ EOF
1890
+
1891
+ # Test 13: Const value from struct (simplified)
1892
+ try_ 99 << EOF
1893
+ struct Point {
1894
+ int x;
1895
+ int y;
1896
+ };
1897
+ int main() {
1898
+ struct Point p = {99, 100};
1899
+ const int val = p.x;
1900
+ return val;
1901
+ }
1902
+ EOF
1903
+
1904
+ # Test 14: Const char array (string)
1905
+ try_ 72 << EOF
1906
+ int main() {
1907
+ const char str[] = "Hello";
1908
+ return str[0]; /* 'H' = 72 */
1909
+ }
1910
+ EOF
1911
+
1912
+ # Test 15: Multiple const on same line
1913
+ try_ 55 << EOF
1914
+ int main() {
1915
+ const int a = 10, b = 20, c = 25;
1916
+ return a + b + c;
1917
+ }
1918
+ EOF
1919
+
1920
+ # Test 16: Const with typedef
1921
+ try_ 88 << EOF
1922
+ typedef int myint;
1923
+ int main() {
1924
+ const myint value = 88;
1925
+ return value;
1926
+ }
1927
+ EOF
1928
+
1929
+ # Test 17: Const void pointer
1930
+ try_ 12 << EOF
1931
+ int main() {
1932
+ int val = 12;
1933
+ const void *ptr = &val;
1934
+ const int *iptr = ptr;
1935
+ return *iptr;
1936
+ }
1937
+ EOF
1938
+
1939
+ # Test 18: Nested const usage
1940
+ try_ 18 << EOF
1941
+ int get_value(const int x) {
1942
+ const int multiplier = 2;
1943
+ return x * multiplier;
1944
+ }
1945
+ int main() {
1946
+ const int input = 9;
1947
+ return get_value(input);
1948
+ }
1949
+ EOF
1950
+
1951
+ # Test 19: Const with pointer arithmetic
1952
+ try_ 30 << EOF
1953
+ int main() {
1954
+ const int arr[] = {10, 20, 30, 40};
1955
+ const int *ptr = arr;
1956
+ ptr = ptr + 2;
1957
+ return *ptr;
1958
+ }
1959
+ EOF
1960
+
1961
+ # Test 20: Const with literal value
1962
+ try_ 3 << EOF
1963
+ int main() {
1964
+ const int x = 3;
1965
+ return x;
1966
+ }
1967
+ EOF
1968
+
1778
1969
# Category: Ternary Operator
1779
1970
begin_category " Ternary Operator" " Testing conditional ?: operator"
1780
1971
0 commit comments