Aims. We want to investigate how planet formation is imprinted on stellar surface composition using up-to-date stellar evolution models.Methods. We simulate the evolution of pre-main-sequence stars as a function of the efficiency of heat injection during accretion, the deuterium mass fraction, and the stellar mass,M⋆. For simplicity, we assume that planet formation leads to the late accretion of zero-metallicity gas, diluting the surface stellar composition as a function of the mass of the stellar outer convective zone. We estimate that in the solar system, between 97 and 168M⊕of condensates formed planets or were ejected from the system. We adopt 150M⊕(M⋆/M⊙)(Z/Z⊙) as an uncertain but plausible estimate of the mass of heavy elements that is not accreted by stars with giant planets, including our Sun. By combining our stellar evolution models to these estimates, we evaluate the consequences of planet formation on stellar surface composition.Results. We show that after the first ~0.1 Myr during which stellar structure can differ widely from the usually assumed fully convective structure, the evolution of the convective zone follows classical pre-main-sequence evolutionary tracks within a factor of two in age. We find that planet formation should lead to a scatter in stellar surface composition that is larger for high-mass stars than for low-mass stars. We predict a spread in [Fe/H] of approximately 0.05 dex for stars with a temperature ofTeff~ 6500 K, to 0.02 dex for stars withTeff~ 5500 K, marginally compatible with differences in metallicities observed in some binary stars with planets. Stars withTeff≤ 7000 K may show much larger [Fe/H] deficits, by 0.6 dex or more, in the presence of efficient planet formation, compatible with the existence of refractory-poorλBoo stars. We also find that planet formation may explain the lack of refractory elements seen in the Sun as compared to solar twins, but only if the ice-to-rock ratio in the solar-system planets is less than ≈0.4 and planet formation began less than ≈1.3 Myr after the beginning of the formation of the Sun.