With the increasing complexity, dynamicity and uncertainty of traffic, motion planning of automatic driving is getting more difficult and challenging. This paper focuses on the real-time motion planning problem of CAVs (connected and automated vehicles) in complex traffic scenarios. To effectively solve this problem, a general driving risk model is presented, which contains the following two essential parts: i) collision risk, i.e., the collision risk between the SV (subject vehicle) and other surrounding vehicles, pedestrians, buildings etc.; ii) non-collision risk, such as violation of traffic regulations, the deviation from the intention of driver, etc. To achieve the real time collision detection, the SV is approximated to a point and its shape is considered by extending the dimension of obstacles considering their relative position and velocity. Then an index similar to the exponential function is defined to calculate the collision risk value, which is composed of the collision detection result and TTC (time to collision). The index of non-collision risk is measured by the deviation from the desired states including regulations, driving manners and intentions etc. Accordingly, a motion planning algorithm by minimizing the aforementioned risk is proposed to calculate the required speed and yaw angle, considering the constraints of vehicle dynamics. Bench tests have been carried out to demonstrate the effectiveness of the proposed motion planning algorithm. The results show that it can safely handle a variety of complex traffic scenarios, such as lane change with a front vehicle cutting in suddenly, meanwhile the traffic regulations and vehicle dynamics constraints can also be met.